Copy respective path next to last column with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy respective path next to last column with awk
# 1  
Old 02-08-2011
Copy respective path next to last column with awk

Hi to all,

I have the short print out sample of the DOS command "dir S/" as showed below.


Code:
 Directory of C:\Program Files\Winamp\Skins\Bento\window

02/12/2010  11:35 p.m.    <DIR>          .
02/12/2010  11:35 p.m.    <DIR>          ..
11/12/2009  10:31 a.m.            13,556 aol_radio_alb_art.jpg
28/04/2009  02:20 p.m.            12,206 config.png
28/04/2009  02:20 p.m.            13,950 controls.png
28/04/2009  02:20 p.m.             2,858 menu_file.png
               4 files            42,570 bytes free
               
 Directory of C:\Program Files\Windows Photo Viewer

14/07/2009  02:48 a.m.    <DIR>          .
14/07/2009  02:48 a.m.    <DIR>          ..
13/07/2009  07:17 p.m.            92,936 ImagingDevices.exe
13/07/2009  07:15 p.m.         1,853,440 ImagingEngine.dll
               2 files         1,946,376 bytes free

Iīve done some custom manipulations with the columns format using sed, but donīt know how to
copy to the rigth (as last column)the respective path above of every block of files as follow.


Code:
 Directory of C:\Program Files\Winamp\Skins\Bento\window

02/12/2010  11:35 p.m.    <DIR>          .
02/12/2010  11:35 p.m.    <DIR>          ..
11/12/2009  10:31 a.m.            13,556 aol_radio_alb_art.jpg  C:\Program Files\Winamp\Skins\Bento\window
28/04/2009  02:20 p.m.            12,206 config.png  C:\Program Files\Winamp\Skins\Bento\window
28/04/2009  02:20 p.m.            13,950 controls.png  C:\Program Files\Winamp\Skins\Bento\window
28/04/2009  02:20 p.m.             2,858 menu_file.png  C:\Program Files\Winamp\Skins\Bento\window
               4 files            42,570 bytes free

 Directory of C:\Program Files\Windows Photo Viewer

14/07/2009  02:48 a.m.    <DIR>          .
14/07/2009  02:48 a.m.    <DIR>          ..
13/07/2009  07:17 p.m.            92,936 ImagingDevices.exe  C:\Program Files\Windows Photo Viewer
13/07/2009  07:15 p.m.         1,853,440 ImagingEngine.dll  C:\Program Files\Windows Photo Viewer
               2 files         1,946,376 bytes free

May somebody help me with this issue?

Thanks in advance.
# 2  
Old 02-08-2011
try:
Code:
awk '/Directory/ {x=gensub("Directory of ","",$0)} $4~/[0-9]/{$NF=$NF" "x}1' file

# 3  
Old 02-08-2011
Code:
awk '/Directory of/ {p=substr($0,15)} $4~/^[0-9]/{$0=$0 FS p}1' infile


Last edited by rdcwayx; 02-08-2011 at 08:18 PM..
# 4  
Old 02-09-2011
Hey guys yinyuemi and rdcwayx, many thanks. Works nice!.
Good lesson, good knowledge learned from your solutions...Smilie
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 copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

2. Shell Programming and Scripting

awk copy first column in new lines

Hi all i have table like this input001_1_174 j 474536 482492 mo001_1_175 j 960192 966656 .ire 966656 984416 .uf/i want copy number of first line to other line... (10 Replies)
Discussion started by: alii
10 Replies

3. Shell Programming and Scripting

Copy files in respective directories

Hi Guys, I need to copy the files to respective directories based on name of the file. My script is something like below con=$1 for file in `cat $con` do file_tmp=$(ls -t1 $path| grep -i $file | head -n 1) echo $file_tmp if then cp $path$file_tmp $DIR/ap if then... (16 Replies)
Discussion started by: Master_Mind
16 Replies

4. UNIX for Advanced & Expert Users

Copy a column to another column in UNIX fixedwidth file

Hi All, I have a fixedwidth file of length 3000. Now i want to copy a column of 4 chars i.e( length 1678-1681) to column 1127 – 1171 to the same file. Please let me know how can i achive using a single command in fixed width file. Also source column length is 4 chars and target column length... (4 Replies)
Discussion started by: kiranparsha
4 Replies

5. Shell Programming and Scripting

Copy column string and put in different column

Hello Here is my input: SU3902 SU3902A NS29C (10) (00) Q1J1 0 SU3902 SU3902B VLR05 (20) (02) Q2H1 4 SU3902 SU3902C NBR22 (30) (06) Q3R5 8 SU3904 SU39047 NSV19 (11) (09) Q4k6 2 SU3904 SU39048 LB231 (12) (05) Q5k1 6 SU3904 SU39049 11VLT (13) (08) Q10C1 10 SU3904 SU3904A 25R05 (15) (06)... (3 Replies)
Discussion started by: pareshkp
3 Replies

6. UNIX for Dummies Questions & Answers

Copy column to another column in unix

Dear Gurus, I have a unix file 2 columns (# delimited) with the following data: ZTXX_CTBR1-ZBRAN1#ZTXX_CTBR1-ZBRAN_DESC# 01#CASH & CARRY# 02#DRUGSTORE - RX# 04#SUPERMARKET# 05#HYPERMARKET# 17#DRUGSTORE - NO RX# I would like to have a code that will do 2 things: 1. Delete the header... (16 Replies)
Discussion started by: chumsky
16 Replies

7. Shell Programming and Scripting

Find all .htaccess files and make a backup copy in respective directories

Hey guys, I need to know how to locate all .htaccess files on the server and make a backup of them in the folder they reside before I run a script to modify all of them. So basically taking dir1/.htaccess and copying it as dir1/.htaccess_bk dir2/.htaccess copying as dir2/.htaccess_bk... (5 Replies)
Discussion started by: boxx
5 Replies

8. Shell Programming and Scripting

A shell script for create a a file in the respective path

Hello forum members, I have to create a out file in the current path./aaa/bbb/ccc/hhh. i am writing script below. ###script Begins##### #!/bin/ksh echo "Weclome" if then echo "Hello" rm -rf $aaa/bbb/ccc/hhh #clean the exsisting o/p file echo "no... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

9. Shell Programming and Scripting

Copy last modified directory from path using Perl

Hi I need to copy last modified directory from path /users/bin to be copied to /tmp in a perl script ...somehow my script is not allowing me to do cd /users/bin. i have tried $dir = `find /users/bin -maxdepth 1 -type d -mtime 0 ` cp -R $dir /tmp/new but it says missing destination... (1 Reply)
Discussion started by: shaveta
1 Replies

10. Shell Programming and Scripting

Copy the data column to adjacent column

Hi, i have file which contains only one record like below a|b|c|.... The no of columns is not known. The expected output is as below: a|a|b|b|c|c|... Please provide me your suggestions. OS: unix Thanks, Selva (7 Replies)
Discussion started by: bharathappriyan
7 Replies
Login or Register to Ask a Question