Command line not recognizing metacharacters in awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Command line not recognizing metacharacters in awk
# 8  
Old 08-13-2014
I misread the original post. I understood it to say that other parts of your processing had problems when there were two digits after the comma; not this code. You sample data only showed us data with single digits before and after the comma and the sample data contained no tab characters (even though the description said that fields were tab separated).

Can you please post a more representative sample input with actual tab characters where they appear in your data and corresponding sample output that should be produced from that input. And, please use CODE tags when displaying both. (If you aren't able to copy and paste tab characters into your message, also show us the output from the command:
Code:
od -bc file

for both your sample input file and your sample output file so we can determine where there should be spaces and where there would be tabs.) And, please answer a few questions:
  1. Do you need to do this with awk, or is sed OK?
  2. Are there supposed to be any spaces in your input file, or are there only tabs between non-whitespace characters?
  3. Will there ever be more than 1 digit before the comma? If so, if there are two digits before the comma and one digit after the comma, should a space still be added before the following tab? What if there are two digits before and two digits after the comma?
  4. Is there always a tab after the digit(s) after the comma in your input file?
  5. Will there ever be any other digits following a comma in your input files? (Your sample data only showed one comma per input line.) If there can be other digits following a comma, are all occurrences to be treated the same way, or is it only the first string containing digits and a comma that is supposed to be processed?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

awk command not replacing in first line

As per requirement if column 2 is NULL then 'N' ELSE 'Y'. I have written below awk code. But it is not replacing values for first line. :confused: cat temp.txt 1|abc|3 1||4 1|11|c awk -F'|' '{if($2==""){$2="N"}else{$2="Y"} print $0 } {OFS="|"} ' < temp.txt 1 Y 3 ... (4 Replies)
Discussion started by: max_hammer
4 Replies

2. Shell Programming and Scripting

Pass awk field to a command line executed within awk

Hi, I am trying to pass awk field to a command line executed within awk (need to convert a timestamp into formatted date). All my attempts failed this far. Here's an example. It works fine with timestamp hard-codded into the command echo "1381653229 something" |awk 'BEGIN{cmd="date -d... (4 Replies)
Discussion started by: tuxer
4 Replies

3. Shell Programming and Scripting

Command line - awk, sed

My input file gfile values is CTRY=GM&PROJTYPE=SP&PROJECTTYPE=Small+Project If i am giving PROJECTTYPE then it must give Small Project awk -F"&" '{for (i=1; i<=NF; i++) if ($i ~ "^"PAT) {sub ("^"PAT"=", "", $i); sed 's/'+'/""/' $i ; print $i }}' PAT=$1 ... (6 Replies)
Discussion started by: nag_sathi
6 Replies

4. UNIX for Dummies Questions & Answers

Need an awk command to delete a line

Hi all, As of now am using an awk command to check the number of columns in a file that has 10 lakh rows. Is it possible to remove that particular line having an extra column and copy the remaining lines to a new file ? YOUR HELP IS HIGHLY APPRECIATED. THANKS IN ADVANCE (5 Replies)
Discussion started by: Rahul619
5 Replies

5. Shell Programming and Scripting

awk - ignore metacharacters, search shell variables

Can I use awk to search for a string, passed from the shell, that might include metacharacters? File1 entries: Bob Marley Jammin (Bonus Track).mp3 File2 entries: Bob Marley Jammin (Bonus Track).mp3 32000 /Music/Bob Marley/ Jammin (Bonus Track).mp3 So far, I have this; $ sed -e... (9 Replies)
Discussion started by: DSommers
9 Replies

6. Shell Programming and Scripting

escaping metacharacters in paths for a shell command

I have a file which contains a list of paths separated by a new line character. e.g /some/path/to/a/file.png /some/path to/another/file.jpeg /some path/to yet/another/file Notice that these paths may contain metacharacters, the spaces for example are also not escaped. If I wanted... (5 Replies)
Discussion started by: cue
5 Replies

7. UNIX for Dummies Questions & Answers

Using current line in a command in AWK

Hi, Im trying to get current line in the AGREP command I use in AWK. My script looks like this: list.txt car bus checklist.txt cer buss cat list.txt | awk -v mycmd="$(agrep -2 -i $0 checklist.txt)" '{print $mycmd}' It doesnt work. How can I get the current line in the $0... (6 Replies)
Discussion started by: m4rty
6 Replies

8. UNIX for Dummies Questions & Answers

The ll command + metacharacters

Hello. I am learning how to use Unix through an online course. Unfortunately the text that we use isn't very good, so I could use some help with a pretty basic question. Use metacharacters and the ll command to list all filenames under the datafiles directory that contain a dot "." with the... (2 Replies)
Discussion started by: feverdream
2 Replies

9. Shell Programming and Scripting

awk pattern matching problem -not recognizing a column

Hi all, I am new to awk. I want to print the line numbers if the column has a particular value. For example I have: cat FILE1 COL1 COL2 X114 0 X116 0 X117 0 X120 0 X121 0 X125 0 X126 0 X127 0 X131 1 X132 0 X135 0 X136 0 (3 Replies)
Discussion started by: newpro
3 Replies

10. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies
Login or Register to Ask a Question