delimiter contents


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delimiter contents
# 1  
Old 01-05-2011
Data delimiter contents

Hi All,

I have a file with contents :
Code:
cat >file1.sh
qw^A34^Aer

the command i am using is:
Code:
cut -f1,2,3 -d"^A" file1.sh

which gave output as:
Code:
qw^A34^Aer

and the command

Code:
cut -f2 -d"^A" file1.sh

gave an output :
Code:
A34

i need the output as :

Code:
34

Please give suggestions as to how can i get the desired output.
Thanks in advance.

Regards,
Sandhya

Last edited by radoulov; 01-05-2011 at 09:23 AM.. Reason: Code tags!
# 2  
Old 01-05-2011
Could you post the output of the following command:

Code:
od -cb file1.sh

# 3  
Old 01-05-2011
Quote:
cut -f2 -d"^A" file1.sh | cut -f2 -d"A"
34
# 4  
Old 01-05-2011
I'll post the output you sent me in private:

Quote:
the output of ur cmd od -cb file1.sh is

Code:
0000000    q   w   ^   A   3   4   ^   A   e   r  \n
         161 167 136 101 063 064 136 101 145 162 012
0000013

but i am unable to understand how it is solving my query...
But now we're able to solve it by providing the proper solution:

Code:
awk -F'\\^A' '{ print $2 }' file1.sh

cut doesn't support multi-character delimiters ...
This User Gave Thanks to radoulov For This Post:
# 5  
Old 01-06-2011
@sed11awk11:

thnks a lot for replyng ...but my input data can have character 'A' in it.. Smilie

@radoulov

thnks a lot for the reply ...it solved my query... Smilie

---------- Post updated 01-06-11 at 12:57 AM ---------- Previous update was 01-05-11 at 09:12 AM ----------

hi,

the command given by radoulov is working while i am using it in command prompt but when i try to use it in a script it is giving me some erronous output...can you suggest a way out of this..

Code:
more file1.sh
qw^A34^Aer

Code:
awk -F'\\^A' '{ print $1 }' file1.sh
qw

this i had used inside a script:
Code:
export a=`awk -F'\\^A' '{ print $1 }' file1.sh`

resulted in :
Code:
$ echo $a
qw^A34^Aer

Smilie

Last edited by radoulov; 01-06-2011 at 05:10 AM.. Reason: Code tags!
# 6  
Old 01-06-2011
below is just a work-around.. Not sure why back-ticks behaves this way.(may be the shell your are running creates this ..?)
Code:
export a=$(awk -F'\\^A' '{ print $1 }' file1.sh)

# 7  
Old 01-06-2011
hi michael,

thanks for the sol..it wrkd...Smilie
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