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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello guys, I am trying to split 1

Status
Not open for further replies.

HIB049

Technical User
Jan 31, 2003
19
GB
Hello guys,

I am trying to split the following line using awk. I have tried every possible unix command sed, awk, cut, and tr, but to not avail.

PLS can you help.

What I am tryin to do is as follows

Line that needs to be processed is as follows:


X11.base.rte 4.3.3.75 COMMITTED AIXwindows Run time Enviro
X11.base.smt 4.3.3.50 COMMITTED AIXwindows Runtimed Shared

I want to split the following above line to the following:

X11.base.rte,4.3.3.75,COMITTED,AIXwindows Run time Enviro
X11.base.smt,4.3.3.50,COMITTED,AIXwindows Runtimed Shared

Can I achieve the above using AWK????????

I have used the following, but its not a perfect solution

echo "X11.base.rte 4.3.3.75 COMMITTED AIXwindows Run time Enviro" | awk -f '{print $1","$2","$3","$4 $5 $6....$n}'

Is there another way of achieving the above????

YOUR HELP WILL BE APPRECIATED.

Ed
THKS.

 
something like this - given the number of fields is variable, but greater than 4.

nawk -f sub.awk myTextFile.txt

#------------ sub.awk
BEGIN {
OFS=","
}

{
match($0,$4);
$4=substr($0, RSTART);
NF=4
print $0
}
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thks very much for that vlad, is there any way of using this on the command line? I do not want to create a file an awk file for this purpose.

Thks
Ed
 
nawk 'BEGIN {OFS=&quot;,&quot;} { match($0,$4);$4=substr($0, RSTART);NF=4;print $0 }' myTextFile.txt vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top