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

Hi i want to insert a pipe symblo in between these columns 1

Status
Not open for further replies.

CALYAN

Programmer
Apr 23, 2001
39
0
0
US
EU The European Union GBP N

I want to insert a pipe symbol between the columns irrespective of the colum bumber.


how to do it with awk?


regards
s.calyan
 
You can do something like this :
Code:
awk '{gsub(FS "+","|") ; print}' input_file

Jean Pierre.
 
Or something like that:

nawk -v OFS='|' '$1=$1' inputFile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
vlad, your command doesn't work on my system.
I tested some variations without success.

The OFS is not used by awk when printing $0, the record is printed as read.

Jean Pierre.
 
are you using awk or nawk?

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
works on my system - Solaris' nawk.
try:
nawk -v OFS='\|' '$1=$1' inputFile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
On my AIX system, awk is nawk.
[tt][n]awk -v OFS='\|' '$1=$1' inputFile[/tt] doesn't work ...



Jean Pierre.
 
strange.
how about:
nawk '$1=$1' OFS='|' inputFile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Doesn't works ..
I also have tried without succes :
[tt]awk 'BEGIN {OFS="|"} $1=$1' inputfile[/tt]

The OFS is used only when I print using ',' operator

[tt]awk -v OFS='|' '{print $1,$2}' inputfile[/tt]

Jean Pierre.
 
seems like the '$1=$1' does not cause the $0 to be reevaluated in your version of 'awk'.

Oh well.....

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
On a Windoze XP computer I put
[tt]
BEGIN{OFS="|"}
$1=$1
[/tt]
in a file and ran awk, mawk, and gawk with [tt] -f t.awk file[/tt]. It worked with all three.
 
I got it !!!
[tt]awk -v OFS='|' '$1=$1 ""' inputfile[/tt]



Jean Pierre.
 
A star to vlad for his very terse solution. Even the "-v" can be eliminated:
Code:
mawk '$1=$1' OFS='|' inputFile
When one of the "filenames" is of the form var=text, it is recognized as an assignment and is performed at the time that argument would be accessed as a file.
 
Sorry, vlad. I just scrolled back and saw that you had already done
[tt]nawk '$1=$1' OFS='|' inputFile[/tt]
 
thanks to all
there is another way i found

:g/../s/type tab/|/g

by substituing

it also works fine

regards
scalyan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top