How-To Extract specific data from a file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How-To Extract specific data from a file.
# 1  
Old 06-21-2016
Hammer & Screwdriver How-To Extract specific data from a file.

data.txt has several information like the below..

Code:
<SERVER>:WEB:MYDOM01:/tmp/cong/MYDOM01,/tmp/app/MYDOM01
<WEBER>:CANES:https-web01,https-web02:/web/apps/https-web01/config

<SERVER>:WEB:MYDOM07:/tmp/cong/MYDOM07,/tmp/app/MYDOM07
<WEBER>:CANES:https-web06,https-web07:/web/apps/https-web07/config
.......
......

I need to read data.txt and pull out all physical paths like the below.
Code:
/tmp/cong/MYDOM01
/tmp/app/MYDOM01
/web/apps/https-web01/config
/tmp/cong/MYDOM07
/tmp/app/MYDOM07
/web/apps/https-web07/config

Need a quick way to achieve this same.

Last edited by Scrutinizer; 06-21-2016 at 03:59 PM.. Reason: quote tags => code tags
# 2  
Old 06-21-2016
Code:
awk -v RS="[:,\n]" '/^\//' inputfile

Use nawk on solaris.
# 3  
Old 06-21-2016
i get the below error:

Code:
awk -v RS="[:,\n]" '/^\//' data.txt
awk: syntax error near line 1
awk: bailing out near line 1

bash-3.2$ uname -a
SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v

# 4  
Old 06-21-2016
Quote:
Originally Posted by Corona688
Use nawk on solaris.
Use nawk on solaris.
# 5  
Old 06-21-2016
Quote:
Originally Posted by Corona688
Use nawk on solaris.
I used nawk but i dont see anything in the output. It's blank.
# 6  
Old 06-21-2016
OK, you have an old awful awk which doesn't support regexes in the field separator.

How about:

Code:
tr ':,' '\n\n' < inputfile | grep '^/'

This User Gave Thanks to Corona688 For This Post:
# 7  
Old 06-21-2016
Quote:
Originally Posted by Corona688
OK, you have an old awful awk which doesn't support regexes in the field separator.

How about:

Code:
tr ':,' '\n\n' < inputfile | grep '^/'

Works good !! Thank you Corona Smilie
This User Gave Thanks to mohtashims For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

2. Shell Programming and Scripting

How to extract specific data?

Bash scripting beginner here... I have many folders, each folder representing one subject. Not all subjects have all the required files, so I need to somehow cycle through all the data and then extract the data only from subjects who have no files missing. I tried to output the ls command, but... (4 Replies)
Discussion started by: LeftoverStew
4 Replies

3. Shell Programming and Scripting

How to extract specific data and count number containing sets from a file?

Hello everybody! I am quit new here and hope you can help me. Using an awk script I am trying to extract data from several files. The structure of the input files is as follows: TimeStep parameter1 parameter2 parameter3 parameter4 e.g. 1 X Y Z L 1 D H Z I 1 H Y E W 2 D H G F 2 R... (2 Replies)
Discussion started by: Daniel8472
2 Replies

4. Shell Programming and Scripting

Extract specific data and change its arrangment

Input: HS04636 PROGRAM source 836 7001 + ID=g1 HS04636 PROGRAM beginner 836 7001 + ID=g1.t1;Parent=g1 HS04636 PROGRAM position 836 836 + Parent=g1.t1 HS04636 PROGRAM type 836 1017 + Parent=g1.t1 HS04636 ... (2 Replies)
Discussion started by: patrick87
2 Replies

5. Shell Programming and Scripting

Extract specific read from a data

Input file: #abc_1 SAASFASFGGDSGDSGDSGSDGSDGSDGSDGSDGSDGSDGDS Output file: FASFGGDSGDS I just want to print out the read from position 5 until position 15 from the data. Below is the code that I just try but it is failed to get my desired output: grep -v '#' input_file | awk... (5 Replies)
Discussion started by: patrick87
5 Replies

6. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

7. Shell Programming and Scripting

Extract all the content after a specific data

My input: >seq_1 DSASSTRRARRRRTPRTPSLRSRRSDVTCS >seq_3 RMRLRRWRKSCSERS*RRSN >seq_8 RTTGLSERPRLPTTASRSISSRWTR >seq_10 NELPLEKGSLDSISIE >seq_9 PNQGDAREPQAHLPRRQGPRDRPLQAYA+ QVQHRRHDHSRTQH*LCRRRQREDCDRLHR >seq_4 DRGKGQAGCRRPQEGEALVRRCS>seq_6 FA*GLAAQDGEA*SGRG My output: Extract all... (22 Replies)
Discussion started by: patrick87
22 Replies

8. Shell Programming and Scripting

Extract data into file with specific field specs

:confused: I have a tab delimited file that I need to extract data from and into a file with specific field specs. Each field has to be a certain amount of characters. So, the name field (from delimited file) might have only 15 characters but needs to be 25 (in new file) so I need to insert spaces... (5 Replies)
Discussion started by: criddel
5 Replies

9. Shell Programming and Scripting

Extract data from log file from or after the specific date

Hi , I am having a script which will start a process and appends the process related logs to a log file. The log file writes logs with every line starting with date in the format of: date +"%Y %b %d %H:%M:%S". So, in the script, before I start the process, I am storing the date as DATE=`date +"%Y... (5 Replies)
Discussion started by: chiru_h
5 Replies

10. Shell Programming and Scripting

extract specific data from xml format file.

Hi, I need to extract the start time value (bold, red font) under the '<LogEvent ID="Timer Start">' tag (black bold) from a file with the following pattern. There are other LogEventIDs listed in the file as well, making it harder for me to extract out the specific start time that I need. . .... (7 Replies)
Discussion started by: 60doses
7 Replies
Login or Register to Ask a Question