04-12-2013
If your fields are tab separated, you can use Yoda's solution if you change
"|" both places where it appears in his script to
"\t".
If fields are separated by a <space> or a mixture of <space> and <tab>, it isn't as easy to do it with awk because awk's default field separator (a space character) is interpreted to mean any combination of one or more space or tab characters.
If you really want to use a single space as your field separator, you could:
- look for a space at the start of a line and replace it with "BAD ",
- look for any occurrence of two spaces together and replace them with " BAD ", and
- look for a space at the end of a line and replace it with " BAD".
If you want to use every <space> or <tab> as a field separator, you could use the directions in the list above but use
look for a space or tab every place where it currently says
look for a space above and use
look for any occurrence of a space or tab immediately followed by a space or tab where it currently says
look for any occurrence of two spaces together. I will leave both of these options as an exercise for the reader.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
I have a file which looks like this
name: Sally group: Group4
name: Tim group: Group1
name: Dan group: Group2
name: Chris group: Group3
name: Peter group:
name: Fred group:
name: Mary group: Group2
Well I want to get rid of the... (4 Replies)
Discussion started by: bombcan
4 Replies
2. UNIX for Dummies Questions & Answers
Hi Guys,
I wanted to count the number of records for a particular field of a file. whose fields are separated by comma","
I fI use this command.
cat "filename" cut -sd "," -f13 | wc -l
This shows all the lines count including the blank values for the field number 13. I wanted to count... (2 Replies)
Discussion started by: Swapna173
2 Replies
3. Shell Programming and Scripting
I have a script with this statement:
/usr/xpg4/bin/awk -F"" 'NR==FNR{s=$2;next}{printf "%s\"%s\"\n", $0, s}' LOOKUP.TXT finallistnew.txt >test.txt
I want to include logic or an additional step that says if there is no data in field 3, move the whole line out of test.txt into an additional... (9 Replies)
Discussion started by: scriptr2be
9 Replies
4. Shell Programming and Scripting
Hi suppose I have a csv file like this
count,1977,1978,1979
usa, , , blue
japan, red, yellow,green
india, , yellow,blue
china, blue, yellow, green
I want the output to be(replace everything, including empty data, with the most recent data):
... (1 Reply)
Discussion started by: grossgermany
1 Replies
5. Shell Programming and Scripting
I have the test data with 10 column separated by comma and each column has more than 1000000 rows. Can anyone help me to find empty field in all columns and delete that empty field alone and lift that column up by one row.
Data with empty field:
A74203XYZ,A21718XYZ,A72011XYZ,A41095XYZ,... (7 Replies)
Discussion started by: zooby
7 Replies
6. Shell Programming and Scripting
I have this
text.filecharles darwin sam delight
george washington johnson culper
darwin sam delight
micheal jackson penny lite and would like to remove the row, if the first field is blank. so the result would be:
result.filecharles darwin sam ... (4 Replies)
Discussion started by: charles33
4 Replies
7. UNIX for Dummies Questions & Answers
Hi all !
I'm sure it is a basic question but I didn't find any threads that fit my need.
How to remove empty fields with awk?
Or in other words, how to shift all the fields after an empty field on the left?
input:
1|2||3|4|5||6
wanted:
1|2|3|4|5|6
I tried:
awk '{for(i=1; i<=NF;... (7 Replies)
Discussion started by: lucasvs
7 Replies
8. Shell Programming and Scripting
I have below file
25-09-2012 24-09-2012 19-09-2012 31-07-2012 30-04-2012 30-03-2012
ASIAEXFVNV N/A CEU 4
DMIRSOA N/A CAS 2 2 2
DMIRSOA N/A MIDMT 2
NFIAL22 N/A HVNY 11 11 11
NFIAL22 N/A NYAL3 11 11 11
NFIAL22 N/A NYCN 11 11 11 ... (4 Replies)
Discussion started by: manas_ranjan
4 Replies
9. Web Development
I have an input form with several fields. What I would like to achieve is to auto populate or copy certain fields if they are empty when the form is submitted. I would like to use php if not then javascript but not jquery if possible - I have sort of had a go but I really have no idea... (4 Replies)
Discussion started by: barrydocks
4 Replies
10. UNIX for Dummies Questions & Answers
Hi all,
I've got a file that has 12 fields. I've merged 2 files and there will be some duplicates in the following:
FILE:
1. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, 100
2. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, (EMPTY)
3. CDC, 54321, TEST3,... (4 Replies)
Discussion started by: tugar
4 Replies