Sponsored Content
Full Discussion: AWK with multiple delimiters
Top Forums Shell Programming and Scripting AWK with multiple delimiters Post 302451376 by bartus11 on Monday 6th of September 2010 04:47:48 PM
Old 09-06-2010
Quote:
Originally Posted by gdub
Works great - Thanks!

---------- Post updated at 09:32 PM ---------- Previous update was at 09:12 PM ----------

BTW - I am trying to capture STDOUT so hence not read a 'file' but passing the string to awk via a pipe. $0 shows the whole string but $1 shows NULL so it doesn't seem to like the delimiters.

eg. I am trying this:
STR="bla bla bla [123] bla bla" #normally the stdout from a command line call of a software product
RUNID=`echo ${STR} | awk -F'[\\[\\]]' '{print $2}'`
echo ${ID}

There's probably a better way to do it but I haven't coded for years.
any ideas?
Try:
Code:
STR="bla bla bla [123] bla bla"
RUNID=$(echo ${STR} | awk -F'[\\[\\]]' '{print $2}')
echo ${RUNID}

BTW, if you wanted to use backticks (`) and (") you would need to do this to make it work (not counting Scrutinizer's solution):
Code:
RUNID=`echo ${STR} | awk -F"[\\\\\[\\\\\]]" '{print $2}'`

which is some terrible abomination to me Smilie
This User Gave Thanks to bartus11 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - treat multiple delimiters as one

Is there anyway to get awk to treat multiple delimiters as one? Particularly spaces... (6 Replies)
Discussion started by: peter.herlihy
6 Replies

2. Shell Programming and Scripting

Cutting a file with multiple delimiters into columns

Hi All I have recently had to start using Unix for work and I have hit brick wall with this prob.... I have a file that goes a little something like this.... EUR;EUR;EUR:USD:USD;USD;;;EUR/USD;XAU/AUD;XAU/EUR;XAU/AUD,GBP/BOB,UAD/XAU;;;1.11;2.22;3.33;4.44;5.55;6.66;;; is it possible to... (7 Replies)
Discussion started by: luckycharm
7 Replies

3. Shell Programming and Scripting

Sorting based on multiple delimiters

Hello, I have data where words are separated by a delimiter. In this case "=" The number of delimiters in a line can vary from 4to 8. The norm is 4. Is it possible to have a script where the file could be separated starting with highest number of delimiters and ending with the lowest An... (8 Replies)
Discussion started by: gimley
8 Replies

4. Shell Programming and Scripting

Sorting problem: Multiple delimiters, multiple keys

Hello If you wanted to sort a .csv file that was filled with lines like this: <Ticker>,<Date as YYYYMMDD>,<Time as H:M:S>,<Volume>,<Corr> (H : , M, S: ) by date, does anybody know of a better solution than to turn the 3rd and 4th colons of every line into commas, sorting on four keys,... (20 Replies)
Discussion started by: Ryan.
20 Replies

5. Shell Programming and Scripting

Use two delimiters in awk

I have a file having lines like: 14: <a="b" val="c"/> 18: <a="x" val="d"/> 54: <a="b" val="c"/> 58: <a="x" val="e"/> I need to create a file with output: 14 d 54 e So basically, for every odd line I need 1st word if delimiter is ':' and for every even... (14 Replies)
Discussion started by: shekhar2010us
14 Replies

6. Shell Programming and Scripting

treating multiple delimiters[solved]

Hi, I need to display the last column value in the below o/p. sam2 PS 03/10/11 0 441 Unable to get o/p with this awk code awk -F"+" '{ print $4 }' pwdchk.txt I need to display 441(in this eg.) and also accept it as a variable to treat it with if condition and take a decision.... (1 Reply)
Discussion started by: sam_bd
1 Replies

7. Shell Programming and Scripting

awk multiple delimiters

Hi Folks, This is the first time I ever encountered this situation My input file is of this kind cat input.txt 1 PAIXAF 0 1 1 -9 0 0 0 1 2 0 2 1 2 1 7 PAIXEM 0 7 1 -9 1 0 2 0 1 2 2 1 0 2 9 PAKZXY 0 2 1 -9 2 0 1 1 1 0 1 2 0 1 Till the sixth column (which is -9), I want my columns to... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

8. Shell Programming and Scripting

Editing phone number with multiple delimiters

Hello all I have a data base of information that is formatted like so: JSD4863 XXX-XX-XXXX DOE, JOHN C JR-II BISS CPSC BS INFO TECH 412/779-9445 I need the last four digits of the phone number. However, many lines contain 'garbage data' that I'm not interested in. So i used a 'for loop'... (7 Replies)
Discussion started by: smartSometimes
7 Replies

9. UNIX for Beginners Questions & Answers

How to append the multiple Delimiters up to requirement?

HI All, How to append the multiple delimiters to at end the file up to 69 fields. FinalDelimiter Count is 69 recrod Delimeter count is 10 so 69-10=59 this script will add upto 59 Delimiters to that records. this script will check each and every record in a file and append the delimiters... (4 Replies)
Discussion started by: vinod.peddiredd
4 Replies

10. Shell Programming and Scripting

Getting fields from a file having multiple delimiters

Hi All, I have a file with a single row having the following text ABC.ABC.ABC,Database,New123,DBNAME,F,ABC.ABC.ABC_APP,"@FUNCTION1("ENT1") ,@FUNCTION2("ENT2")",R, I want an output in the following format ABC.ABC.ABC DBNAME ABC.ABC.ABC_APP '@FUNCTION1("ENT1")... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies
RCVPACK(1)							     [nmh-1.5]								RCVPACK(1)

NAME
rcvpack - append message to file SYNOPSIS
/usr/lib/mh/rcvpack file [-mbox] [-mmdf] [-version] [-help] DESCRIPTION
The rcvpack program will append a copy of the message to the file listed on its command line. If the -mbox switch is given (the default), then the messages are separated using mbox (uucp) style delimiters. This is the format used by most mail clients (elm, mailx, etc.). If the -mmdf switch is given, then the messages are separated by mmdf style delimiters. Each message in the file is separated by four CTRL-A's and a newline. rcvpack will correctly lock and unlock the file to serialize access to the file, when running multiple copies of rcvpack . In general, its use is obsoleted by the file action of slocal, although it might still have occasional uses in various shell scripts. FILES
/etc/nmh/mts.conf nmh mts configuration file SEE ALSO
rcvdist(1), rcvstore(1), rcvtty(1), slocal(1) BUGS
Only two return codes are meaningful, others should be. MH.6.8 11 June 2012 RCVPACK(1)
All times are GMT -4. The time now is 09:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy