Print files with spaces using awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Print files with spaces using awk
# 8  
Old 04-01-2011
gensub is the function of GNU awk, so how about in this way:

Code:
find . -ls |
gawk -F'.' 'NR>1{print ($1~/dr/)?"D."$NF:"F."$NF}' |
gawk -F'./' 'NF==2&&/^D/{print substr($0,2),"(--D--)","(--root--)","(--UniqueID "NR"--)"}
NF>2&&/^D/{;match($0,/.*\//);print substr($0,2),"(--D--)","(--"substr($0,2,RLENGTH-RSTART-1)"--)","(--UniqueID "NR"--)"}
/^F/{;match($0,/.*\//);print  substr($0,2),"(--F--)","(--"substr($0,2,RLENGTH-RSTART-1)"--)","(--UniqueID "NR"--)"}'
 
./folder2 (--D--) (--root--) (--UniqueID 1--)
./folder2/file6 (--F--) (--./folder2--) (--UniqueID 2--)
./folder1 (--D--) (--root--) (--UniqueID 3--)
./folder1/folder11 (--D--) (--./folder1--) (--UniqueID 4--)
./folder1/folder11/file3 (--F--) (--./folder1/folder11--) (--UniqueID 5--)
./folder1/folder11/file4 (--F--) (--./folder1/folder11--) (--UniqueID 6--)
./folder1/file2 (--F--) (--./folder1--) (--UniqueID 7--)
./folder1/file\ 1 (--F--) (--./folder1--) (--UniqueID 8--)
./folder4 (--D--) (--root--) (--UniqueID 9--)
./folder4/file5 (--F--) (--./folder4--) (--UniqueID 10--)
./folder3 (--D--) (--root--) (--UniqueID 11--)


Last edited by yinyuemi; 04-01-2011 at 06:24 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk print string with removing all spaces

Hi all, I want to set 10 set of strings into a variable where: removing all spaces within each string change the delimiter from "|" to "," Currently, I've the below script like this:Table=`ten character strings with spaces in-between and each string with delimiter "|" | tr -d ' ' |... (7 Replies)
Discussion started by: o1283c
7 Replies

2. Shell Programming and Scripting

awk - print columns with text and spaces

Hi, I'm using awk to print columns from a tab delimited text file: awk '{print " "$2" "$3" $6"}' file The problem I have is column 6 contains text with spaces etc which means awk only prints the first word. How can I tell awk to print the whole column content as column 6? Thanks, (10 Replies)
Discussion started by: keenboy100
10 Replies

3. UNIX for Dummies Questions & Answers

AWK print last field including SPACES

I have simple test.sh script, see below: bill_code=`echo $record | awk -F"|" '{print $1}'` Fullname=`echo $record | awk -F"|" '{print $3}'` email=`echo $record | awk -F\ '{print $4}'` The last field contains spaces: see csv below: A0222|Y|DELACRUZ|-cc dell@yahoo.com-cc support@yahoo.com ... (9 Replies)
Discussion started by: quay
9 Replies

4. Shell Programming and Scripting

Compare two files and print using awk

I have 2 files: email_1.out 1 abc@yahoo.com 2 abc_1@yahoo.com 3 abc_2@yahoo.com data_1.out <tr> 1 MAIL # 1 TO src_1 </tr> <tr><td class="hcol">col_id</td> <td class="hcol">test_dt</td> <td class="hcol">user_type</td> <td class="hcol">ct</td></tr> <tr><td... (1 Reply)
Discussion started by: sol_nov
1 Replies

5. Shell Programming and Scripting

AWK help print dirs with files in it

Hi, I'm writing some start of day checks for my work. I want to check some dirs for files that have been created longer than 10 mins ago and not been transfered. I've already used a find command to write a list of files that meet this criteria to a log called sod.log i.e. ... (1 Reply)
Discussion started by: elcounto
1 Replies

6. Shell Programming and Scripting

use awk print statement for two files

Hello, is there a way to use the awk print statement on two files at once? I would like to take two columns from one file, and one column from another file and print them as consecutive columns to a third file. Seems simple...as in: file 1 1 a 2 b 3 c 4 d 5 e file 2 1 t 2 u... (3 Replies)
Discussion started by: HugoHuhn
3 Replies

7. Shell Programming and Scripting

Print filenames with spaces using awk

Hello all, I want to list the file contents of the directory and number them. I am using la and awk to do it now, #ls |awk '{print NR "." $1}' 1. alpha 2. beta 3. gamma The problem I have is that some files might also have some spaces in the filenames. #ls alpha beta gamma ... (7 Replies)
Discussion started by: grajp002
7 Replies

8. Shell Programming and Scripting

Print to 2 files in awk if statement

Hi all, I have some code like this awk -F, '{ if ($1==3) print $2 > "output_file" print "1" > "new_file" }' "input_file" When I check output_file this has the correct values in it. However the new_file has 1 in it for every line in the input_file. If the input file has 20 lins then... (2 Replies)
Discussion started by: Donkey25
2 Replies

9. Shell Programming and Scripting

How to print arguments along with spaces using awk

Hi All, file_1.txt contains aaa bbbb hhhh vvvvv mmmmm iiiii What i want is to search for the first coloumn of each line using awk.i.e as below: awk '/aaa/ {printf(<>)}' file_1.txt The print part (<>) should contain all the values(or coloumns ) in the particular line(here it... (8 Replies)
Discussion started by: jisha
8 Replies

10. Shell Programming and Scripting

awk print fields to multiple files?

I am trying to print the output of a command to two separate files. Is it possible to use awk to print $1 to one file and $2 to another file? Thanks in advance! (1 Reply)
Discussion started by: TheCrunge
1 Replies
Login or Register to Ask a Question