from - to delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting from - to delimiter
# 1  
Old 03-13-2008
Data from - to delimiter

hey guys can you please help me out,

i'm having problem in cutting strings. I need a delimiter to cut string.

sample
Code:
a.txt
"ID", "1234" , "iam bighippo", "help!"
"ID", "1235" , "again0", "xxxxxxx1"
"ID", "1236" , "again1", "xxxxxxx2"
"ID", "1237" , "again2", "xxxxxxx3"

how do i cut "1234" , "ID" , "iam bighippo" and store it into a variable?
Code:
ID="ID"
NUM="1234"
NAME="iam bighippo"

is there a function that cuts the string using delimiter? Thanks!
# 2  
Old 03-13-2008
Check out the man pages of cut.
# 3  
Old 03-13-2008
What I understand from the problem given below is that you are confused over using delimiters in the string.

If the string is same as what you have given , then "," can be used as a delimiter and the value can be stored in a variable as well.
Example below:

id=`cat a.txt | cut -d "," -f 1`

If "," is not something you intend to use as a delimiter, you can use space as a delimiter.Example given below:

id=`cat a.txt | tr -s " " | cut -d " " -f 1`

Hope this helps!

Thanks!
nua7
# 4  
Old 03-13-2008
thanks for quick reply.
ok.. now how do i store it in a variable?
so far i can only store the filtered sting in a text file..
# 5  
Old 03-13-2008
what exactly you want to store in the variable.? My eg shows how to store filtered string in the variable. Sorry but can't get your question..
# 6  
Old 03-13-2008
what exactly are you wanting to do. ? show your output.
# 7  
Old 03-13-2008
i got it all working now! thank you nua7!
sorry, im just a newbie in shell script.
anyway thanks for your response
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

how to get everything before the last delimiter?

hi all, i have a string with a number of "/"s as delimiter. and i want everything BEFORE the last delimiter i know to use basename to get everything after the last delimiter. thx a lot! (2 Replies)
Discussion started by: sunnydanniel
2 Replies

4. 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

5. Shell Programming and Scripting

Help regarding the delimiter

Hi, I am trying to load data from a file to oracle DB. The file am using has a ";" as a delimiter. While I load the file, I want to check whether the file is having the correct delimiter or not. if not, the file should not be processed. Is there any way that i could handle this scenario using... (3 Replies)
Discussion started by: smileyreddy
3 Replies

6. UNIX for Dummies Questions & Answers

unconstant delimiter

I have file with unconstatnt delimiter for each field which are non-printable characters like tab and space file 6271 manchester (tab) 11/09/09 200 accepted 6272 manchester (tab) 11/09/09 200 accepted I want only first... (7 Replies)
Discussion started by: tsurendra
7 Replies

7. Shell Programming and Scripting

cut -d with more than 1 delimiter?

I need to cut or otherwise get the 4th and 5th position output of for i in `date +%H` ; do vnstat --dumpdb | grep "h;$i" ; done example output is: h;13;1310318701;443;93 I only need ";443;93" from any given run of "for i in `date +%H` ; do vnstat --dumpdb | grep "h;$i" ; done" Thanks... (3 Replies)
Discussion started by: Habitual
3 Replies

8. 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

9. UNIX for Dummies Questions & Answers

Delimiter

I am having the following file. I need to insert a delimiter in this file. I used sed but its not working. AAABBB 9 JJJ AAABBC 9 TTTTT AAABBA 8 JJJ AAABBC 7 TTTTT AAABBC 6 TTTTT Now i want the output file as: AAA|BBB| |9| |JJJ| AAA|BBC| |9| | |TTTTT| (3 Replies)
Discussion started by: sivakumar.rj
3 Replies

10. Shell Programming and Scripting

replace the last delimiter

hi, i have a file of the below format: WA| 3|52|Waste | PW| 3|53|Promotion Waste | BR| 3|54|Breakage | TH| 3|55|Theft | IC| 3|56|Insurance Claim | I want to replace the last delimiter | by using sed command ...can u please help me witht this Thanks in... (4 Replies)
Discussion started by: jisha
4 Replies
Login or Register to Ask a Question