delimiter contents


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delimiter contents
# 8  
Old 01-06-2011
You need one more backslash with the old command substitution command:

Code:
export a=`awk -F'\\\^A' '{ print $1 }' file1.sh`

But, of course, you should use the new one $( ... ), if your shell supports it.
These 2 Users Gave Thanks to radoulov For This Post:
# 9  
Old 01-06-2011
Quote:
Originally Posted by radoulov
You need one more backslash with the old command substitution command:

Code:
export a=`awk -F'\\\^A' '{ print $1 }' file1.sh`

But, of course, you should use the new one $( ... ), if your shell supports it.
Thanks radoulov. I have two question wrt the field separator. If the field separator is ^A in the file, why do we have 2 backslashes, i thought one would be enough.If 2 backslashes it mean literally FS= \^A

Wrt your recent post..How does adding another one backslash to the existing 2 backslashes work in the script.?
This User Gave Thanks to michaelrozar17 For This Post:
# 10  
Old 01-06-2011
Quote:
I have two question wrt the field separator.
If the field separator is ^A in the file, why do we have 2 backslashes, i thought one would be enough.
If 2 backslashes it mean literally FS= \^A
Good questions.
From the GNU awk manual (p 46,-47 from rhe pdf version)

Quote:
... with Unix awk and gawk, the
assignment ‘FS = "\.."' assigns the character string ".." to FS (the backslash is stripped).
This creates a regexp meaning “fields are separated by occurrences of any two characters.”
If instead you want fields to be separated by a literal period followed by any single character,
use ‘FS = "\\.."'.
So in the assignment you loose one backslash and in order to get \^ you need \\^.

Quote:
How does adding another one backslash to the existing 2 backslashes work in the script.?
This is special to the old-style backquote form of substitution `...`, it just removes a \
when it's followed by another \, from the manual pages of bash:

Quote:
When the old-style backquote form of substitution is used, backslash retains its literal meaning except when
followed by $, `, or \. The first backquote not preceded by a backslash terminates the command substitution.
When using the $(command) form, all characters between the parentheses make up the command; none are treated
specially.
Code:
% printf '%s\n'  `printf '%s' '\\a'`  
\a
% printf '%s\n'  $(printf '%s' '\\a') 
\\a

# 11  
Old 01-06-2011
Quote:
Originally Posted by radoulov
So in the assignment you loose one backslash and in order to get \^ you need \\^.
Here the delimiter of file file1.sh is ^A..am i correct? If so then why we have the delimiter literally \^A as you have said above.
# 12  
Old 01-06-2011
Quote:
Originally Posted by michaelrozar17
Here the delimiter of file file1.sh is ^A..am i correct? If so then why we have the delimiter literally \^A as you have said above.
The awk FS contains either a single character or a multi-character regular expression.
Therefore the ^ is special (a zero-width match at the beginning of the string) and
if you need to match a literal ^, you need to escape it.

Last edited by radoulov; 01-06-2011 at 07:33 AM..
# 13  
Old 01-06-2011
Is the field separator a literal "^A" or SOH (ASCII Start of Header)? If it is SOH, I do not see any reason for the guarding backslashes.

Both
Code:
$ cut -f2 -d'^A' infile
34

and
Code:
$ a=$(awk -F'^A' '{ print $2 }' infile); print $a
34

work perfectly well for me if SOH is entered as CTRL-V,CTRL-A.
# 14  
Old 01-06-2011
Quote:
Originally Posted by fpmurphy
Is the field separator a literal "^A" or SOH (ASCII Start of Header)? If it is SOH, I do not see any reason for the guarding backslashes.

Both
Code:
$ cut -f2 -d'^A' infile
34

and
Code:
$ a=$(awk -F'^A' '{ print $2 }' infile); print $a
34

work perfectly well for me if SOH is entered as CTRL-V,CTRL-A.
It's not the case, please read post #4.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If contents of A are in B then move the common contents to C

Hallo Team, I have 2 .csv files file A has 47600 lines and file B has 67000 lines FILEA SD0o9rb01-1d320ddbcc8d220f572739ebed5f58d1-v300g00 SD8bt0101-a0810bfe0e3396060126ec51b30dac0a-v300g00 SD05sce01-cb056af347ed4651f29eb3c3e9addbd6-v300g00... (3 Replies)
Discussion started by: kekanap
3 Replies

2. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

3. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

4. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

5. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

6. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

Hi all, I have a number of strings like below: //mnt/autocor/43°13'(33")W/ and i'm trying to get the numbers in this string, for example 431333 please help thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies

7. Shell Programming and Scripting

I want to delete the contents of a file which are matching with contents of other file

Hi, I want to delete the contents of a file which are matching with contents of other file in shell scripting. Ex. file1 sheel,sumit,1,2,3,4,5,6,7,8 sumit,rana,2,3,4,5,6,7,8,9 grade,pass,2,3,4,5,6,232,1,1 name,sur,33,1,4,12,3,5,6,8 sheel,pass,2,3,4,5,6,232,1,1 File2... (3 Replies)
Discussion started by: ranasheel2000
3 Replies

8. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

9. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

10. UNIX for Dummies Questions & Answers

Seperate contents in a file with | as delimiter

Hi, I do have a file with follwoing as contents: 816|817118| 816|933370| 816|1215241| I want to store the above values into two arrays as follows: arr1 = { 816,816,816} arr2 = {817118,933370,1215241} How it can be achieved ? (5 Replies)
Discussion started by: risshanth
5 Replies
Login or Register to Ask a Question