Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am looking for help on sed programming.

Status
Not open for further replies.

a2715mt

Programmer
Dec 15, 2004
2
US
I couldn't find it in the search group.
Do we have one?

Thanks,
 
I am looking for help on sed programming
man sed

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Try the Unix Scripting forum. Lots of posts there involving sed.
 
Well. I was trying to modiying part of the code somebody else wrote.
I found a better web forum:


A lot of good unix programmers can answer scripting related questions or problems.
 
Here are 3 awk questions I found on that site.

----------------------------------------------------------
echo "$names"
The outout of this is JOHN,MIKE,EAGLES,SCOTT,MIKE1,JOHN2.....................etc like these names (70 names in a single line)

I am getting the below error if i execute the below line with the above names
var1=`echo "$names" | awk -F, '{print NF}'`

awk: record `JOHN,MIKE,EAGLES,SCOTT,MIKE1,JOHN2........................' too long

------------------------------------------------------
Probably needs to use nawk.

------------------------------------------------------
Suppose I have a following file "tmpFile" :

'1111,aaa '
'2222,bbbb '

excluding single quotes, those I have shown in order to signify the presence of
trailing spaces at the end of the record.

Now if I run following command,
awk -F"," '{printf("%s:%s\n", $1,$2) }' tmpFile

$2 field is read as-
'aaa '
'bbbb '

Actually at the time of reading, I would like to read as -
'aaa'
'bbbb'

----------------------------------------------------------
The solution given was:
Code:
awk -F',' '{gsub(/[\t ]*$/,"",$2);print $2}' datafile
sub(), not gsub(), should be used since only 1 match is being replaced. [\t ]* should be [\t ]+ since * means 0 or more occurrances; if there are 0 occurrances, there's nothing to replace.
And since the spaces are at the end of the line, this would do: [tt]sub(/[\t ]+$/,"")[/tt]

-----------------------------------------------------
Fred Smith and Sue Brown
Joe Jones and Jane Watts
Sally Green and Jim O?
Connor
Freda O?
Reiley and Pat O?
Connell
Peter Parker and Tina Williams
need to be changed to
Fred Smith and Sue Brown
Joe Jones and Jane Watts
Sally Green and Jim O?Connor
Freda O?Reiley and Pat O?Connell
Peter Parker and Tina Williams

----------------------------------------------------
The solution was
Code:
{ if ( $0 ~ /\?$/ ) {
    line=line$0;
    next;
  } else {
     print line$0;
  }
  line="";
}
Too long, and he thinks Awk is C (semicolons everywhere).
Code:
/\?$/ { line = line $0; next }
{ print line $0; line = "" }
 
everything is relative in this world - USENET [wink]

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top