cancel
Showing results for 
Search instead for 
Did you mean: 

field separator

 
SOLVED
Go to solution
Shivkumar
Super Advisor

field separator

Dear Sirs,

I am using $ps -ef|awk '{print $2 $3}'.
I want to insert field separator between two fields to distinguish the output.

Can anyone help me ?

Thanks,
Shiv
7 REPLIES 7
Yogeeraj_1
Honored Contributor
Solution

Re: field separator

hi

try:
ps -ef|awk '{print $2 " " $3}'

regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: field separator

hi again,

the separator can be any character that you would be putting between the double quotes:

e.g. "-" or "|"

ps -ef|awk '{print $2 "|" $3}'

or ps -ef|awk '{print $2 "-" $3}'

regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Kasper Hedensted
Trusted Contributor

Re: field separator

Hi,

You also use a comma if you just want to seperate in 2 columns

$ps -ef|awk '{print $2,$3}'

Cheers,
Kasper
Cem Tugrul
Esteemed Contributor

Re: field separator

Shiv,

you can both use " " and , between line
selections so;
$ps -ef|awk '{print $2,$3}'
or
ps -ef|awk '{print $2 " " $3}'

Good Luck,
Our greatest duty in this life is to help others. And please, if you can't
Sandman!
Honored Contributor

Re: field separator

Shivkumar,

You can customize the field separator to whatever you want i.e. comma, bar, carriage return etc. as long as you specify it within your awk construct like:

# ps -ef | awk '{OFS="";print $2, $3}'
Vibhor Kumar Agarwal
Esteemed Contributor

Re: field separator

I'll say go by the Sandman's OFS.

There will be many situations where you have to use OFS.
Situations like where your field data contains spaces, tabs and special characters then only OFS will come to your rescue.
Vibhor Kumar Agarwal
Highlighted
Amit Agarwal_1
Trusted Contributor

Re: field separator

You can further use printf instead of print to have more control over the output.

ps -ef|awk '{printf("%s | %s\n", $2,$3);}'

-Amit