Parsing a file using unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing a file using unix
# 1  
Old 10-22-2010
Parsing a file using unix

I have the following input file

Code:
$AGENCY_SCRIPTS/mfa_pools_avlbal.sh get
$AGENCY_SCRIPTS/daily_db_tables.sh
$AGENCY_SCRIPTS/missing_prefix_new.sas
$AGENCY_SCRIPTS/fnma-arm-matrix.pl
$AGENCY_SCRIPTS/fnma_mega_dus.sh curr
$AGENCY_SCRIPTS/fhlm_supp_daily.c
$AGENCY_SCRIPTS/run_fhlm_prepay.sh daily curr
$AGENCY_SCRIPTS/read_embs_daily_dataset.sh fhlm fhlm_breakout_daily.data curr
$AGENCY_SCRIPTS/read_embs_daily_dataset.sh fhlm fhlm_daily.data curr
$AGENCY_SCRIPTS/run_fhlm_daily_pools.sh fhlm curr fhlm_daily.data
$AGENCY_SCRIPTS/update_daily_database.sh fhlm pools
$AGENCY_SCRIPTS/update_daily_database.sh fhlm issuer
$AGENCY_SCRIPTS/run_fhlm_daily_arm.sh fhlm curr
$AGES_SHARED_SCRIPTS/update_daily_database.sh fhlm arm
$AGENCY_SCRIPTS/update_daily_database.sh fhlm strata
$AGENCY_SCRIPTS/fhlm_wgt_lnsz_dly.sh curr
/bin/touch $AGY_PIPELINE_DAILY/gnm2.daily.ready
$AGENCY_SCRIPTS/mex_pipe.sh fnma.arm daily
/bin/touch $AGY_PIPELINE_DAILY/fnma.daily.ready
$AGENCY_SCRIPTS/read_daily_arm_pool.sh
/bin/rm -f $EMBS_TRIGGER_DIR/*_daily.ready

I need this output:
Code:
$AGENCY_SCRIPTS		mfa_pools_avlbal.sh
$AGENCY_SCRIPTS		daily_db_tables.sh
$AGENCY_SCRIPTS		missing_prefix_new.sas
$AGENCY_SCRIPTS		fnma-arm-matrix.pl
$AGENCY_SCRIPTS		fnma_mega_dus.sh
$AGENCY_SCRIPTS		fhlm_supp_daily.c
$AGENCY_SCRIPTS		run_fhlm_prepay.sh
$AGENCY_SCRIPTS		read_embs_daily_dataset.sh
$AGENCY_SCRIPTS		read_embs_daily_dataset.sh
$AGENCY_SCRIPTS		run_fhlm_daily_pools.sh
$AGENCY_SCRIPTS		update_daily_database.sh
$AGENCY_SCRIPTS		update_daily_database.sh
$AGENCY_SCRIPTS		run_fhlm_daily_arm.sh
$AGES_SHARED_SCRIPTS	update_daily_database.sh
$AGENCY_SCRIPTS		update_daily_database.sh
$AGENCY_SCRIPTS		fhlm_wgt_lnsz_dly.sh
$AGENCY_SCRIPTS		mex_pipe.sh
$AGENCY_SCRIPTS		read_daily_arm_pool.sh


Last edited by vgersh99; 10-22-2010 at 06:31 PM.. Reason: code tags, please!
# 2  
Old 10-22-2010
Code:
awk -F[/\ ] '/^\$AGE/ {print $1,$2}'  inputfile

# 3  
Old 10-22-2010
Code:
grep -v ^/ inputfile | sed 's:\([^/][^/]*\)/\([^ ][^ ]*\).*:\1 \2:'


Last edited by ctsgnb; 10-22-2010 at 06:47 PM..
# 4  
Old 10-22-2010
Code:
awk -F/ '$1~/\$.*SCRIPTS/{printf "%-24s %s\n",$1,$2}' infile

Code:
$ awk -F/ '($1=$1)&&!/^\//' infile

Code:
sed '/^\//d;s|/| |' infile

# 5  
Old 10-22-2010
Quote:
Originally Posted by Scrutinizer
Code:
awk -F/ '$1~/\$.*SCRIPTS/{printf "%-24s %s\n",$1,$2}' infile

Code:
$ awk -F/ '($1=$1)&&!/^\//' infile

Code:
sed '/^\//d;s|/| |' infile

In your last 2 statements, where would you remove the 3rd field and + when present ? (lines wher "read_embs_daily_dataset.sh" occures for example)
# 6  
Old 10-22-2010
Code:
$ ruby -ne 'puts $_.split(/[\/ ]/,3)[0,2].join("%+10s"%"\t") if $_[/^\$/]' file

$AGENCY_SCRIPTS                 mfa_pools_avlbal.sh
$AGENCY_SCRIPTS                 daily_db_tables.sh
$AGENCY_SCRIPTS                 missing_prefix_new.sas
$AGENCY_SCRIPTS                 fnma-arm-matrix.pl
$AGENCY_SCRIPTS                 fnma_mega_dus.sh
$AGENCY_SCRIPTS                 fhlm_supp_daily.c
$AGENCY_SCRIPTS                 run_fhlm_prepay.sh
$AGENCY_SCRIPTS                 read_embs_daily_dataset.sh
$AGENCY_SCRIPTS                 read_embs_daily_dataset.sh
$AGENCY_SCRIPTS                 run_fhlm_daily_pools.sh
$AGENCY_SCRIPTS                 update_daily_database.sh
$AGENCY_SCRIPTS                 update_daily_database.sh
$AGENCY_SCRIPTS                 run_fhlm_daily_arm.sh
$AGES_SHARED_SCRIPTS            update_daily_database.sh
$AGENCY_SCRIPTS                 update_daily_database.sh
$AGENCY_SCRIPTS                 fhlm_wgt_lnsz_dly.sh
$AGENCY_SCRIPTS                 mex_pipe.sh
$AGENCY_SCRIPTS                 read_daily_arm_pool.sh

# 7  
Old 10-22-2010
Quote:
Originally Posted by ctsgnb
In your last 2 statements, where would you remove the 3rd field and + when present ? (lines wher "read_embs_daily_dataset.sh" occures for example)
Nowhere Smilie
Code:
sed -n '/^\//d;s/ .*//;s|/| |p' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Parsing UNIX emails

Hi all, I am new to unix and I have a requirement to develop a shell script which does the following:- Check for email from a particular user If found, copy the attachment in the mail to a particular directory. Delete the email. Any help, pointers are really appreciated. Thanks (3 Replies)
Discussion started by: esgovi1234
3 Replies

2. Shell Programming and Scripting

Specific string parsing in Linux/UNIX

Hi, I have a string which can be completely unstructred. I am looking to parse out values within that String. Here is an example <Random Strings> String1=<some number a> String2=<some number b> String3=<some number c> Satish=<some number d> String4=<some number e> I only want to parse out... (1 Reply)
Discussion started by: satishrao
1 Replies

3. Windows & DOS: Issues & Discussions

Parsing a UNIX txt to separate files

I have a requirement to parse a dataflex .txt file and break it into separate files within the Windows server env. Is there any special characters I should pay particular attention on the unix side? Any ideas? Thanks in advance (2 Replies)
Discussion started by: kicklinr
2 Replies

4. UNIX for Advanced & Expert Users

XML parsing by UNIX

Hi, I am new in shell scripting. i want to extract tag values in xml files by using shell script. my files like this: <cw: properties> <cw:std_properties> <tns: properties> <tns:name>AdminOutQueue</tns:name> <tns:type>String</tns:type> <tns:subtype>QueueName</tns:subtype> <tns:value... (25 Replies)
Discussion started by: arindam guha
25 Replies

5. Shell Programming and Scripting

New to UNIX ... Date parsing

Hi ... extremely new to Unix scripting ... I have to get a date field from mm/dd/yyyy to yyyy/mm/dd format ... I have a variable that I want parsed. I don't seem to be doing it right?? Thanks. (19 Replies)
Discussion started by: MJKeeble
19 Replies

6. Shell Programming and Scripting

string parsing using UNIX

I got multple sql files.such as >>vi abc.sql select A.SITENAME, NULL NULL A.CREATE_DTM NULL A.MODIFY_DTM NULL FROM ${STG_RET_ITEM} A INNER JOIN ${STG_INC_COMP} B ON (A.CUSTID=B.CUSTID) LEFT OUTER JOIN ( select C.SITEID,SITESTATUS,MIN_EFF_DT,CURR_ST_DT,MAX_IN_DT,MAX_ACT_DT from... (4 Replies)
Discussion started by: ali123
4 Replies

7. Shell Programming and Scripting

File parsing in Unix

I have got a large file with content as below. LOCATION A B C 1 Line 3 Line 4 *Line 8 **Line 9 TAG END LOCATION A B" C 3 Line 33 Line 34 (4 Replies)
Discussion started by: rinku11
4 Replies

8. Programming

Parsing unix STAT structure

Hi I am creating a utility which needs to create a log file under the path represented by an environment variable. The condition is that this path must be a valid DIRECTORY PATH. So i need to determine that the path is indeed a VALID DIRECTORY PATH. I have written a function which will return... (2 Replies)
Discussion started by: skyineyes
2 Replies

9. UNIX for Advanced & Expert Users

html parsing using unix

hi all, I had raised the same question a few weeks back but forgot to mention a lot of points ... so i am raising a new thread furnishing my requirement ... sorry for that .... here is my problem. i have a html that look like below <tr class="modifications-oddrow"> <td... (2 Replies)
Discussion started by: sais
2 Replies

10. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies
Login or Register to Ask a Question