LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Blogs
User Name
Password

Notices


Old

BASH replace a line in file

Posted 04-05-2020 at 05:20 PM by karanis
Tags bash

sed "s|a dumb string|$lan|g" file.txt

sed "s|#dns_server\t\t10.0.0.1:53|#dns_server 192.168.1.1:53|g" /tmp/baresip_config
LQ Newbie
Posted in Uncategorized
Views 42 Comments 0 karanis is offline
Old

BASH extract fields from string

Posted 04-05-2020 at 05:19 PM by karanis
Tags awk, bash

https://en.wikibooks.org/wiki/Cut

link above have nice examples

Examples of use of similar tools in cut's domain:

echo a b|awk '{print $2}'
Displays "b", separating fields by any number of tabs or spaces. Thus, for awk, "b" is the 2nd field, while for cut -d" ", "b" is the 3rd field.
echo a b|awk '{print $2 $1}'
Displays "ba", preserving the order of the fields as specified....
LQ Newbie
Posted in Uncategorized
Views 41 Comments 0 karanis is offline
Old

BASH read file

Posted 04-05-2020 at 05:17 PM by karanis
Tags bash

https://www.cyberciti.biz/faq/unix-h...ine-from-file/

https://www.computerhope.com/unix/bash/read.htm

https://www.shellhacks.com/bash-read...ead-line-loop/

----------

while read USER; do echo "Hello $USER!"; done < users.txt

----------

#!/bin/ksh
file="/home/vivek/data.txt"
while IFS= read line
do
# display $line...
LQ Newbie
Posted in Uncategorized
Views 41 Comments 0 karanis is offline
Old

BASH datetime for scripts

Posted 04-05-2020 at 05:16 PM by karanis
Tags bash, time

#!/bin/bash
dt=`date '+%d/%m/%Y %H:%M:%S'`
echo "$dt"
LQ Newbie
Posted in Uncategorized
Views 36 Comments 0 karanis is offline
Old

BASH get ip from ifconfig ( and grep hostname from /etc/hosts by IP)

Posted 04-05-2020 at 05:13 PM by karanis
Updated 04-05-2020 at 05:15 PM by karanis
Tags bash, net

#!/bin/bash

IP=`/usr/sbin/ip addr show dev eth0| grep -v inet6| awk ' !/127.0.0.1/ && /inet/ { gsub(/\/.*/, "", $2); print $2 }'`
grep $IP /etc/hosts | sed -r s/$IP\\s\\t//
LQ Newbie
Posted in Uncategorized
Views 42 Comments 0 karanis is offline

  



All times are GMT -5. The time now is 02:15 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration