using awk with space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using awk with space
# 1  
Old 04-12-2005
using awk with space

when printing using awk how can i print all the fields on 1 line?

Code:
#!/bin/sh
awk '{print $1 $2 $3}'

givesMeOutputLikeThis

whereas

Code:
awk '{print $1 " " $2 " " $3}'

gives
Me
Output
Like
This

I would like to line like this -> "gives Me Output Like This"
# 2  
Old 04-12-2005
use commas instead of spaces in your first code ...
# 3  
Old 04-12-2005
you mean like this
Code:
awk '{print $1,$2,$3}'

it still gives me the same output as the second code
# 4  
Old 04-12-2005
Quote:
Originally Posted by strike
when printing using awk how can i print all the fields on 1 line?

Code:
#!/bin/sh
awk '{print $1 $2 $3}'

givesMeOutputLikeThis

whereas

Code:
awk '{print $1 " " $2 " " $3}'

gives
Me
Output
Like
This

I would like to line like this -> "gives Me Output Like This"
what does your input look like?
# 5  
Old 04-12-2005
im using it to print a line from a file with just some certain fields

Code:
#!/bin/sh
for SOMELINE in `grep "hello there" $FILE | awk '{print $1 $2 $3}'`
do
  echo $SOMELINE
done

# 6  
Old 04-12-2005
Quote:
Originally Posted by strike
you mean like this
Code:
awk '{print $1,$2,$3}'

it still gives me the same output as the second code
strange ... since i get right on mine ...
Code:
root_mybox:/root # echo "1 2 3 4 5" | awk '{print $1,$3,$5}' 
1 3 5
root_mybox:/root # echo "1 2 3 4 5" | awk '{print $1 $3 $5}' 
135
root_mybox:/root #


Last edited by Just Ice; 04-12-2005 at 10:59 AM.. Reason: extra things ...
# 7  
Old 04-12-2005
hmmzz, very strange indeed
are u using bourne shell for that script?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create the space only in the Third column by awk

Hi All , I am having an input file like this Input file r s e y Pin Numbers s n eppppppppppppppppppc ... (3 Replies)
Discussion started by: kshitij
3 Replies

2. Shell Programming and Scripting

awk to escape space in name

I am searching a file and not able to escape a space if $i has a space in the name. I tried escaping it with a \ and also trying to add it to allow for spaces in the search. Neither are correct as the first awk only outputs path and the second awk doesn't run. Thank you :). first awk awk... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Need to use delimiter as : and space in awk

Hi , Please suggest me how do I use : (colon and one space) as a delimiter in awk Best regards, Vishal (2 Replies)
Discussion started by: Vishal_dba
2 Replies

4. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

5. Shell Programming and Scripting

awk print used space

Hi Team, Can you please tell me how to get a used space in KB LINUX and free space in KB separate commands. For example: $df -k /rer (apdfp01.xxx.com:/var/adm/rash/MT) : 2066900 total allocated Kb 4579 free allocated Kb 16121 used allocated Kb 89 % allocation used /dev/deviceFS1... (5 Replies)
Discussion started by: indira_s
5 Replies

6. Shell Programming and Scripting

AWK - Ignoring White Space with FS

I have an AWK script that uses multiple delimiters in the FS variable. FS="+" My awk script takes a file name such as this: 12345_smith_bubba_12345_20120215_4_0.pdf and parses it out based on the under score. Each parsed field then has some code for data validation etc. This script has... (12 Replies)
Discussion started by: reno4me
12 Replies

7. Shell Programming and Scripting

Space with awk

Hi, Need some help with awk and blank fieds.. # last -n 2 gml4410 pts/0 host3 Fri Nov 18 07:46 - 07:53 (00:06) nmc5060 host2 Thu Nov 17 15:29 - 15:30 (00:00) I need to extract field1(userid) , field5(month) and field 6(day). Notice the second line has blank space... (2 Replies)
Discussion started by: vignes10
2 Replies

8. UNIX for Dummies Questions & Answers

awk for variable with a space

Hi experts, why does $ echo "one two three" | awk '{$3="my tree"; print $0}' one two my tree work, but $ var="my tree" $ echo "one two three" | awk '{$3="'$var'"; print $0}' awk: {$3="my awk: ^ unterminated string does not work? How can the variable tha contains a space be... (2 Replies)
Discussion started by: GermanicGalore
2 Replies

9. Shell Programming and Scripting

Replacing / with a space using awk

I have a string and want to replace the / with a space. For example having "SP/FS/RP" I want to get "SP FS RP" However I am having problems using gsub set phases = `echo $Aphases | awk '{gsub(///," ")}; {print}'` (5 Replies)
Discussion started by: kristinu
5 Replies

10. Shell Programming and Scripting

Search with awk, but having space within

If in my search string with awk, if I have spaces, I am getting an awk error. e.g. awk /A B/ filename How can I search the pattern which has space within? (1 Reply)
Discussion started by: videsh77
1 Replies
Login or Register to Ask a Question