awk facing delimiter inside data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk facing delimiter inside data
# 1  
Old 02-10-2014
awk facing delimiter inside data

Inpu file is as below:
Code:
CMEOPT1_dump.1:1002 ZN:VTJ3J3C131
CMEOPT1_dump.1:1002 ZN:VTM4M4P123%5
CMEOPT1_dump.1:1002 ZN:VTM3M3P132%5
CMEOPT1_dump.2:1002 OZNG4
CMEOPT2_dump.3:1002 ZB:VTH4H4C132
CMEOPT2_dump.4:1002 ZN:VTK4K4P123
CMEOPT2_dump.5:1002 ZN:BOZ2Z2Z2P131%5
CMEOPT2_dump.5:1002 OZNG4

I am trying to write an awk statement should give me output as:

Code:
1002 ZN:VTJ3J3C131
1002 ZN:VTM4M4P123%5
1002 ZN:VTM3M3P132%5
1002 OZNG4
1002 ZB:VTH4H4C132
1002 ZN:VTK4K4P123
1002 ZN:BOZ2Z2Z2P131%5
1002 OZNG4

--Please help
# 2  
Old 02-10-2014
What have you tried so far?
# 3  
Old 02-10-2014
Many option i tried with different combination. Tried with multiple delimeter option also.. but no luckSmilie
# 4  
Old 02-10-2014
If the data in the file is as it is, then below might work:

cut -f2,3 -d':' infile

thanks
# 5  
Old 02-10-2014
Thanks for your response.. But awk is mandatory in my case.. is there a possibility in awk?

---------- Post updated at 10:54 AM ---------- Previous update was at 10:51 AM ----------

also what will happen if my 2nd field has two colons?

Thanks
# 6  
Old 02-10-2014
Code:
$ awk '{print NF == 3 ? $2 OFS $3 : $2}' FS=":" OFS=":" file

OR
Code:
$ awk '{$0 = NF == 3 ? $2 OFS $3 : $2}1' FS=":" OFS=":" file

Code:
1002 ZN:VTJ3J3C131
1002 ZN:VTM4M4P123%5
1002 ZN:VTM3M3P132%5
1002 OZNG4
1002 ZB:VTH4H4C132
1002 ZN:VTK4K4P123
1002 ZN:BOZ2Z2Z2P131%5
1002 OZNG4

This User Gave Thanks to Akshay Hegde For This Post:
# 7  
Old 02-10-2014
It seems some sort of school exercise.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can awk ignore the field delimiter like comma inside a field?

We have a csv file as mentioned below and the requirement is to change the date format in file as mentioned below. Current file (file.csv) ---------------------- empname,date_of_join,dept,date_of_resignation ram,08/09/2015,sales,21/06/2016 "akash,sahu",08/10/2015,IT,21/07/2016 ... (6 Replies)
Discussion started by: gopal.biswal
6 Replies

2. Shell Programming and Scripting

Scripting with awk: facing problem

Hi, I wants to print the 9th column information with its path name in some txt file. Here is one line which works fine for me: rfdir /castor/cern.ch/user/s/sudha/forPooja | grep data | awk '{print "rfio:///castor/cern.ch/user/s/sudha/forPooja/"$9}' > dataFilenames.list rfdir=="ls -ltr" ... (2 Replies)
Discussion started by: nrjrasaxena
2 Replies

3. Shell Programming and Scripting

Help with data re-arrangement problem facing

Input file: <symbol>Q9Y8G1</symbol> <name>Q9Y8G1_EMENI</name> <symbol>Q6V953</symbol> <symbol>Q5B8K1</symbol> <name>Q6V953_EMENI</name> <symbol>G1A416</symbol> <name>G1A416_9FUNG</name> <symbol>D4N894</symbol> <name>D4N894_PLEER</name> <symbol>B0FFU4</symbol>... (13 Replies)
Discussion started by: cpp_beginner
13 Replies

4. Shell Programming and Scripting

Replacing Comma delimiter coming inside the data.

Hello, I am having flat file (Comma Delimiter) and the data in the file is as given below. EMPNO, ENAME, DESIGNATION, SALARY 10979, Arun Kumar, Cosultant, 35000 13555, Bidhu Shekar, Senior Consultant, 45000 15000, Kiran, Kumar, Senior, Consultant, 40000 If... (9 Replies)
Discussion started by: arunvasu2
9 Replies

5. Shell Programming and Scripting

Exporting data into Comma Delimiter.

Hi, Requirement: Exporting data from Oracle to UNIX into "Comma" delimiter. Help Needed: I was able to connect to Oracle and import the data. But please let me know while importing the data I need to make it into Comma delimiter flat file. For Example: Source Data - 100 ABC TLead... (6 Replies)
Discussion started by: arunvasu2
6 Replies

6. Shell Programming and Scripting

Problem facing in using awk command

Hi., I am not able to replace the string with another string using gsub fn of awk command. My code: awk 'BEGIN gsub(004,IND,004)' p.txt and my i/p file p.txt is of the format: av|004|adkf|Kent,004|s av|005|ssdf|Kd,IT park|s . . . and my desired o/p should be of : (13 Replies)
Discussion started by: av_vinay
13 Replies

7. UNIX for Dummies Questions & Answers

How to get data only inside polygon created by points which is part of whole data from file?

hiii, Help me out..i have a huge set of data stored in a file.This file has has 2 columns which is latitude & longitude of a region. Now i have a program which asks for the number of points & based on this number it asks the user to enter that latitude & longitude values which are in the same... (7 Replies)
Discussion started by: reva
7 Replies

8. Shell Programming and Scripting

Manipulate data in detail problem facing

Input Participant number: HAC Position type Location Distance_start Distance_end Range Mark 1 1 + Front 808 1083 276 2 1 + Front 1373 1636 264 3 1 - Back 1837 2047 211 Participant number: BCD Position type... (6 Replies)
Discussion started by: patrick87
6 Replies

9. Shell Programming and Scripting

append data in a file by using tab delimiter

Hi, I need to append the data in to a file by using tab delimiter. eg: echo "Data1" >> filename.txt echo "\t" >> filename.txt (its not working) echo "Data2" >> filename.txt. the result sould be like this. Data1 Data2 (6 Replies)
Discussion started by: Sharmila_P
6 Replies

10. Shell Programming and Scripting

Problem facing with sed and awk

Hi All, I have a got a problem .. I have t files as below: 1.txt contains ----- ----- ----- column 1, "cat", column 24, "dog", column 100, "rat", ----- ----- ----- 2.sh should contain ----- ----- ----- awk 'BEGIN { printf ("%1s","cat")}' (19 Replies)
Discussion started by: jisha
19 Replies
Login or Register to Ask a Question