awk facing delimiter inside data

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk facing delimiter inside data
# 8  
Old 02-10-2014
You could also try any of the following awk scripts:
awk '{sub(/.*:/, "", $1);print}' file
awk '{$1 = substr($1, 16);print}' file
awk '{$1 = substr($1, length($1) - 3);print}' file

One or all of them might work for you depending on how closely your actual input matches the sample input you provided.
# 9  
Old 02-10-2014
And some more for fun:
awk '{$1=x}sub(/:/,x)' FS=: OFS=: file
awk -F'^.*:' '{print $2}' file
awk -F: 'sub($1 FS,x)' file

The latter happens to work, because the . (any character) matches the literal dot..

sed not allowed either?
sed 's/[^:]*://' file

# 10  
Old 02-14-2014
awk -F":" '{print $2,$NF}'

---------- Post updated at 07:09 AM ---------- Previous update was at 07:08 AM ----------

awk -F":" '{print $2,$NF}' file

Last edited by Scott; 02-14-2014 at 09:39 AM.. Reason: Code tags, please
# 11  
Old 02-14-2014
Originally Posted by 24ajay
awk -F":" '{print $2,$NF}'

---------- Post updated at 07:09 AM ---------- Previous update was at 07:08 AM ----------

awk -F":" '{print $2,$NF}' file
Unfortunately, unlike many of the other proposals that have been made in this thread, this suggestion adds an unwanted trailing space to to the output for input lines that contain one colon character, and deletes all colons from the desired output when there are two or more colon characters on an input line. If there are more than two colons on an input line, this code drops even more of the desired output.
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/ | grep data | awk '{print "rfio:///castor/"$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", ----- ----- ----- should contain ----- ----- ----- awk 'BEGIN { printf ("%1s","cat")}' (19 Replies)
Discussion started by: jisha
19 Replies
Login or Register to Ask a Question