Stuck on a text find and append task


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Stuck on a text find and append task
# 1  
Old 01-23-2014
Stuck on a text find and append task

Hi,

Bit of a tricky one for first post and hoping someone can help me out here.

I've got some code that I'm trying to consolidate by taking the first line where it says "OUTPUT", remove the : and append it after a space where the are occurences of ".csv", and then take the next occurence of "OUTPUT", remove the : and do the same.

So this is what the data looks like:

OUTPUT_20110812_256921/20110901:
Code:
total 123454453
-rwxrwxrwx   1 testuser testuser 29343434 Sep 12 15:59 DUMMY.csv
-rwxrwxrwx   1 testuser testuser       8 Sep 12 15:59 DUMMY.control

OUTPUT_20110916_223232/20110912:
Code:
total 26786786878
-rwxrwxrwx   1 testuser testuser   11111 Oct  5 04:27 ALPHA.csv
-rwxrwxrwx   1 testuser testuser       2 Oct  5 04:27 ALPHA.control
-rwxrwxrwx   1 testuser testuser  22222 Oct  9 04:00 BETA.csv
-rwxrwxrwx   1 testuser testuser       4 Oct  9 04:00 BETA.control

...and this is what I'm trying to get to (for every line with a .csv in):
Code:
-rwxrwxrwx   1 testuser testuser 29343434 Sep 12 15:59 DUMMY.csv OUTPUT_20110812_256921/20110901
-rwxrwxrwx   1 testuser testuser   11111 Oct  5 04:27 ALPHA.csv OUTPUT_20110916_223232/20110912
-rwxrwxrwx   1 testuser testuser  22222 Oct  9 04:00 BETA.csv OUTPUT_20110916_223232/20110912

Can anyone help please? Smilie

Last edited by Franklin52; 01-24-2014 at 08:56 AM.. Reason: Please use code tags
# 2  
Old 01-23-2014
Hello,

It's a request please use code tags for commands input and output as per forum rules. Also following code may help you.

Code:
awk '/OUTPUT/ {f=$0}; /.csv/ {g=$0" "f} gsub(/\:/,X,g) {print g}' check_data_file_in_line

output will be as follows.

Code:
-rwxrwxrwx 1 testuser testuser 29343434 Sep 12 1559 DUMMY.csv OUTPUT_20110812_256921/20110901
-rwxrwxrwx 1 testuser testuser 11111 Oct 5 0427 ALPHA.csv OUTPUT_20110916_223232/20110912
-rwxrwxrwx 1 testuser testuser 22222 Oct 9 0400 BETA.csv OUTPUT_20110916_223232/20110912


Thanks,
R. Singh
# 3  
Old 01-23-2014
Thank you so much and noted about the code tag. Smilie
# 4  
Old 01-23-2014
Try also
Code:
awk 'NF==1 {sub(/:/,""); P=$1} /csv$/ {print $0,P}'  file
-rwxrwxrwx 1 testuser testuser 29343434 Sep 12 15:59 DUMMY.csv OUTPUT_20110812_256921/20110901
-rwxrwxrwx 1 testuser testuser 11111 Oct 5 04:27 ALPHA.csv OUTPUT_20110916_223232/20110912
-rwxrwxrwx 1 testuser testuser 22222 Oct 9 04:00 BETA.csv OUTPUT_20110916_223232/20110912

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to preserve the same text and modify the same text to append?

Hi, I have an issue modifying a file. Below is the content of the file. File name - a.txt SELECT LISTAGG(SCORE), LISTAGG(VB), LISTAGG(SCORE*12 + 3), LISTAGG(DOB) from T_CONCAT ; SELECT LISTAGG(SCORE), LISTAGG(VB), LISTAGG(SCORE*100 + 3), from... (1 Reply)
Discussion started by: Mannu2525
1 Replies

2. UNIX for Beginners Questions & Answers

Need list of input and output parameter of task in a text file, using shell script

//file begin ===== //some code task abcd_; input x; input y,z; //some comment output w; //some comment reg p; integer q; begin //some code end endtask : abcd_ //some code //file end ===== expected output from above... (1 Reply)
Discussion started by: rishifrnds
1 Replies

3. Shell Programming and Scripting

Find and Append

I'm not sure this is the *best* idea but it's what occurs to me: I have a long bibliographical list where the entries are in a variety of forms. So, there's no consistent format. I can pretty much find the year of publication buried in each line. Everything else is a bit of a mess. So, human... (5 Replies)
Discussion started by: fred3
5 Replies

4. Shell Programming and Scripting

sed - Find a String and append a text end of the Line

Hi, I have a File, which have multiple rows. Like below 123456 Test1 FNAME JRW#$% PB MO Approver XXXXXX. YYYY 123457 Test2 FNAME JRW#$% PB MO Super XXXXXX. YYYY 123458 Test3 FNAME JRW#$% PB MO Approver XXXXXX. YYYY I want to search a line which contains PB MO Approver and append... (2 Replies)
Discussion started by: java2006
2 Replies

5. Shell Programming and Scripting

Use sed to append text to filenames if text not already present

I have some html with hrefs that contain local links to pdf filenames. These filenames should have standardised names, i.e. there should be a label prior to the ".pdf" filename suffix. There can be many of these links on a single line of text and some may already have the label. For example ... (13 Replies)
Discussion started by: adb
13 Replies

6. Shell Programming and Scripting

find a certain line and append text to the end of the line

After I create printer queues in AIX, I have to append a filter file location within that printers custom file. within lets say test_queue.txt I need to find the row that starts with :699 and then I need to append on the end the string /usr/local/bin/k_portrait.sh. Now I've gotten the sed... (2 Replies)
Discussion started by: peachclift
2 Replies

7. Shell Programming and Scripting

Cut and append the text

I have a text like this ... i need append the text whihc is after 'csb' into the end of the line input ----- sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl sdir;csp oc_lib-0.10.4;bdir;cbpdob ---enable-useosstl output sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl... (6 Replies)
Discussion started by: girija
6 Replies

8. Shell Programming and Scripting

comment and Uncomment single task out of multiple task

I have a file contains TASK gsnmpproxy { CommandLine = $SMCHOME/bin/gsnmpProxy.exe } TASK gsnmpdbgui { CommandLine = $SMCHOME/bin/gsnmpdbgui.exe I would like to comment and than uncomment specific task eg TASK gsnmpproxy Pls suggest how to do in shell script (9 Replies)
Discussion started by: madhusmita
9 Replies

9. UNIX for Dummies Questions & Answers

Stuck with a simple find problem

Hi, Need some simple find help. I need to search for all .so files within sol directory. My directory tree has mix of directories and i want to search only inside sol directory. I could get this done combining find with for, any option to do this with find alone. for a in `find .... (13 Replies)
Discussion started by: vibhor_agarwali
13 Replies

10. Shell Programming and Scripting

Text Append

I'm creating a script that counts the number of users currently online, then records that in a file called "log.txt" along with the time. Everytime the script is ran, the script appends the "log.txt" this is what I have: who|wc|cut -c6,7>>log.txt date|cut -c12-24>>log.txt After running... (5 Replies)
Discussion started by: 801238429
5 Replies
Login or Register to Ask a Question