extracting few characters from a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers extracting few characters from a file
# 1  
Old 01-02-2008
extracting few characters from a file

i want to extract few characters from a file based on a special character like ||
how to do it
suggestions please
# 2  
Old 01-02-2008
Please provide an example of your file and what you want to extract. Perhaps then we can help you.
# 3  
Old 01-03-2008
Hi,
I have a line called 1001||PO Box 123||Chicago||IL||60699
In this line I want to extract the comma separated values like
1001
PO Box 123
Chicago
IL
60699


How to do the same
# 4  
Old 01-03-2008
Code:
# for i in `echo "1001||PO Box 123||Chicago||IL||60699" | tr  "|" " "`
> do
>     echo $i
> done
1001
PO
Box
123
Chicago
IL
60699

# 5  
Old 01-03-2008
your sample line is not comma separated. the separator in it is two pipes. Use this Perl script:
Code:
#!/usr/bin/perl
# extract.pl
while (<>) {
    print join ("\n", split (/\|\|/, )), "\n";
}

run this script as:
Code:
perl extract.pl double_piped_file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extracting range of characters if pattern matches

Im trying compare values between files and if they match I want to extract some characters in between those values for many files. They are in two directories and have the name filename but one ends in .enr. They look like this. cat bat.1.enr name,start,end bat.1,231, 234 and another... (5 Replies)
Discussion started by: verse123
5 Replies

2. Shell Programming and Scripting

Extracting characters and storing in some variable

eg: ./myProgram.sh filename.cpp I want to remove the :".cpp" extension from the filename.cpp expected output: filename (3 Replies)
Discussion started by: umesh314
3 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Extracting all characters from a string

I want to extract the string TC from the string TC10, the string can have any characters out of . I used the following code but didnt get the right output. Please guide nuc=match(val,/*/) seq=substr(val,RSTART,RLENGTH) ---------- Post updated at 09:40 PM ---------- Previous update was... (0 Replies)
Discussion started by: newbie83
0 Replies

4. Shell Programming and Scripting

Extracting data between two characters

From the command line how would I extract data in file that was contained between parenthesis "()"? Awk or Grep? Thanks in advance Ted (11 Replies)
Discussion started by: TedSD
11 Replies

5. Shell Programming and Scripting

Extracting specific characters from a text file

I'm extremely new to scripting and linux in general, so please bear with me. The class I'm taking gives virtually no instruction at all, and so I'm trying to learn everything off the web. Anyway, I'm trying to extract characters that follow after a specific pattern ( '<B><FONT FACE="Arial">' ) but... (3 Replies)
Discussion started by: livos23
3 Replies

6. Shell Programming and Scripting

Parsing file, yaml file? Extracting specific sections

Here is a data file, which I believe is in YAML. I am trying to retrieve just the 'addon_domains" section, which doesnt seem to be as easy as I had originally thought. Any help on this would be greatly appreciated!! I have been trying to do this in awk and mostly bash scripting instead of perl... (3 Replies)
Discussion started by: Rhije
3 Replies

7. UNIX for Dummies Questions & Answers

Advice on extracting special characters from a DB2 table to a file in the UNIX ENV

need some advice on the following situation. I have a DB2 table which has a varchar Column. This varchar column can have special characters like ©, ®, ™ . When I extract from this table to a sequential file for this varchar column I am only able to get © and ® . To Get the ™... (1 Reply)
Discussion started by: cosec
1 Replies

8. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies

9. Shell Programming and Scripting

[Splitting file] Extracting group of segments from one file to others

Hi there, I need to split one huge file into separate files if the condition is fulfilled according to that the position between 97 and 98 matches with “IT” at the segment MAS. There is no delimiter file is fix-width with varous line length. Could you please help me how I do split the file... (1 Reply)
Discussion started by: ozgurgul
1 Replies

10. Shell Programming and Scripting

extracting usernames with at least 4 characters

Hi, i want to use grep to extract users with at least 4 characters in their username, i've tried who | grep \{4,\} but thats not working!!!!!! Thanks (4 Replies)
Discussion started by: c19h28O2
4 Replies
Login or Register to Ask a Question