[Solved] awk FS


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] awk FS
# 1  
Old 09-12-2013
[Solved] awk FS

I have a script which uses awk to read from a file seperated with commas, although saved as a .conf file.

Code:
 awk -F, '{print $3}'

it is meant to pick up "a label here" (for example)

But instead return "a"

Problem is that although the command does recognise the comma seperation it still recognises blank sapces also as deilimiters, which means the next command printing the $4 variable is picking up the blank space " ".

Is there any way to get awk to completely ignore blank spaces and just use the commas as delimiters? The field I am reading must remain as it is and I cannot remove the spaces.

---------- Post updated at 04:02 AM ---------- Previous update was at 03:55 AM ----------

sorry problem solved.

The issue was with the rest of the command, which was:
Code:
KEY_LBL=`printf ${FILE}| awk -F, '{print $3}'`

However I changed it to:
Code:
KEY_LBL=`echo ${FILE}| awk -F, '{print $3}'`

and it now works a treat. Simple echo / printf issue.
# 2  
Old 09-12-2013
Could you please post the content of your file?

Usually awk wont consider the space as default separator when -F is used.

Code:

Code:
vidya> awk -F, '{print $3}' vv
c d e
vidya> cat vv
a,b,c d e,e f,g
vidya>

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] awk Errors on notation

can someone spot what i'm doing wrong here: awk 'BEGIN{printf("%0.2f", 1 / 2649320) * 100}' i get this error: awk: line 1: syntax error at or near * then i do this and get the answer i'm trying to avoid: awk 'BEGIN{print(1 / 2649320) * 100}' 3.77455e-05 (7 Replies)
Discussion started by: SkySmart
7 Replies

2. UNIX for Dummies Questions & Answers

[Solved] awk oddity

I have to apologize for my ignorance so this question is probably stupid. How does awk process a file? Does it read from top of input file to end of file going line by line? Yoda helped me create an awk script that helps me parse the named.conf file and output it into a .csv file but when... (8 Replies)
Discussion started by: djzah
8 Replies

3. Shell Programming and Scripting

[Solved] Using awk to calculate max value

I have a file of sites and each site has a variable number of flow values with a date for each value. I want to determine the max value of flow for each site and output the site number, max value, and date of max value.The format structure (simplified) is the following: Record Site Number ... (5 Replies)
Discussion started by: cparr
5 Replies

4. UNIX for Dummies Questions & Answers

[Solved] To the power of using awk

Hi Guys, I got stuck to a a point where I need to find the value for (4 to the power of -2 upto 8 places after decimal .... 4^(-2) ; the result I need is upto 8 places after decimal. How is that possible? Thanks a lot!! (2 Replies)
Discussion started by: Indra2011
2 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Help with awk

Hi All, I have been using the below syntax in unix and it has been working fine, Later when we migrated to Linux by having folder wise pemission its not working fine. So can you let us know where the list file could be created ? awk '/^XXX/{key=$0;print > "list";next} /^YYY/ {print... (4 Replies)
Discussion started by: secretsanta.rci
4 Replies

6. Shell Programming and Scripting

[Solved] HP-UX awk sub multiple patterns

Hi, I am using sub to remove blank spaces and one pattern(=>) from the input string. It works fine when I am using two sub functions for the same. However it is giving error while I am trying to remove both spaces and pattern using one single sub function. Working: $ echo " OK => " |awk... (2 Replies)
Discussion started by: sai_2507
2 Replies

7. Shell Programming and Scripting

[Solved] awk string with spaces

Why does this work: awk -v s="this is a string" 'index($0, s)' file while the following doesn't? s="this is a string" awk -v s=$s 'index($0, s)' file How do I search for a string with spaces in it? ---------- Post updated at 01:18 AM ---------- Previous update was at 01:15 AM ----------... (0 Replies)
Discussion started by: locoroco
0 Replies

8. Shell Programming and Scripting

[Solved] Split file using awk

hlow all, need your advice i have sample.txt 1252468812,yahoo,3.5 1252468812,hotmail,2.4 1252468819,yahoo,1.2 1252468812,msn,8.9 1252468923,gmail,12 1232468819,live,3.4 1252368929,yahoo,9.0 1252468929,msn,1.2now i want filtering with awk so output will like this 12524_log.txt... (2 Replies)
Discussion started by: zvtral
2 Replies

9. Shell Programming and Scripting

Solved: AWK SED HELP

Hi, I need to process a file as below. Could you please help to achieve that using awk/sed commands. Input file: --------------- AB | "abcdef 12345" | 7r5561451.pdf PQRST | "fghfghf hgkjgtjhghb ghhgjhg hghjghg " | 76er6ry.pdf 12345 | "fghfgcv uytdywe bww76 jkh7dscbc 78 : nvchtry hbuyt"... (0 Replies)
Discussion started by: viveksr
0 Replies

10. Shell Programming and Scripting

can this been solved with awk and sed?

Hi Masters, ___________________________________________________________________________________ Group of orthologs #1. Best score 3010 bits Score difference with first non-orthologous sequence - yeast:3010 human:2754 YHR165C 100.00% PRP8_HUMAN 100.00%... (16 Replies)
Discussion started by: mskcc
16 Replies
Login or Register to Ask a Question