understand sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting understand sed
# 1  
Old 06-02-2015
understand sed

Code:
cat teledir.txt
jai sharma 25853670
chanchal singhvi 9831545629
anil aggarwal 9830263298
shyam saksena 23217847
lalit chowdury 26688726

If i use the below command , it is giving me the output with "," in between two name. how ? and also i would like to know the reason for the space used in between ([a-z]*\) *\([a-z]*\) and \2, \1/' and what is the use of specifying two [a-z] and what *\ means?

Code:
sed 's/\([a-z]*\) *\([a-z]*\)/\2, \1/' teledir.txt | sort

aggarwal, anil 9830263298
chowdury, lalit 26688726
saksena, shyam 23217847
sharma, jai 25853670
singhvi, chanchal 9831545629


Last edited by joeyg; 06-02-2015 at 02:50 PM.. Reason: Please wrap scripts/commands and data inside CodeTags
# 2  
Old 06-02-2015
Quote:
Originally Posted by ANTONY ANKROSE
.
.
.
If i use the below command , it is giving me the output with "," in between two name. how ?
Because you told it to with \2, \1 (the "replacement" string)

Quote:
and also i would like to know the reason for the space used in between ([a-z]*\) *\([a-z]*\)
to separate given from family name
Quote:
and \2, \1/'
to swap and separate family from given name
Quote:
and what is the use of specifying two [a-z]
one for given, one for family name
Quote:
and what *\ means?
Nothing. * is the repeater/multiplier for the preceding "atom" (character(s)), \ escapes the char to follow.

May I advise reading man sed and man regex?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help me understand this script

#!/bin/awk -f BEGIN {i=1;file="modified.txt"} { if ($0 !~ /^DS:/) {print $0 >> file} else { if ($0 ~ /^DS:/) {print "DS: ",i >> file;if (i==8) {i=1} else {i++}}; } } END {gzip file} Can someone explain to me how this above script works, I got it from a friend but not able... (3 Replies)
Discussion started by: Kamesh G
3 Replies

2. Shell Programming and Scripting

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

3. Shell Programming and Scripting

can't understand!

Hi All, can you please help me to figured out what's the meaning of this. ${SERVER_DATABASE} -b << EOF 2>>/dev/null THanks, (3 Replies)
Discussion started by: nikki1200
3 Replies

4. Shell Programming and Scripting

I can't understand sed error output.

Hey forum, I have a problem with a script what used to work, but suddenly is not working anymore. I have been trying different things for an hour now and I give up :D . #!/bin/sh asukoht=`pwd` template=$1 for values in... (4 Replies)
Discussion started by: mario8eren
4 Replies

5. Shell Programming and Scripting

Can't understand the script

I am relatively new to Shell Scripting. I can't understand the following two scripts. Can someone please spare a minute to explain? 1) content s of file a are (021) 654-1234 sed 's/(//g;s/)//g;s/ /-/g' a 021-654-1234 2)cut -d: -f1,3,7 /etc/passwd |sort -t: +1n gives error (3 Replies)
Discussion started by: shahdharmit
3 Replies

6. Shell Programming and Scripting

trying to understand what sed is doing?

Can someone help me understand why sed '/host/ s/$/QQQ/g' junk is taking the file 'junk' which is this: host Example_1 filename-"gfnwd.cfg"; hardware-ethernet-00:13:11:fd:7a:88; fixed-address-10.10.6.19; } host Example_2 filename-"gfnwd_280.cfg";... (2 Replies)
Discussion started by: TheBigAmbulance
2 Replies

7. Shell Programming and Scripting

Sed command - help me understand

Hello, can someone please explain me what the following commands do.. i know the output but i would like to understand the break down of what they do step by step. 1) sed -n "/ $(date +\%R -d "-1 min")/,$"p req.txt| wc -l 2) awk '/19:00/,/22:00/' app.log |grep "mytesturl"|grep... (2 Replies)
Discussion started by: niks
2 Replies

8. UNIX for Dummies Questions & Answers

can't understand this at all.

Ok, i've been trying to write some shell scripts. nothing challenging, but just automating All of the tutorials i read say to start the file with #!/bin/bash or whatever your path to bash is. So i do it, and all of my scripts error out saying ./nameofscript:command not found when i... (4 Replies)
Discussion started by: severndigital
4 Replies

9. UNIX for Dummies Questions & Answers

can't understand

how i can download this game n start it :S (5 Replies)
Discussion started by: BoyArcher
5 Replies
Login or Register to Ask a Question