Awk with Find and play using Space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk with Find and play using Space
# 1  
Old 01-10-2012
Awk with Find and play using Space

Hi All,

Sample records
HTML Code:
2157 91128 -rw-r-----  1 arun1    staff    93315072 Aug 23 06:44 /home/arun/my own/file_name.txt
2157 91128 -rw-r-----  1 arun1    staff    93315072 Aug 23 06:44 /home/arun/myown/file name2.txt
i want to print only user name, user group, size, date time stamp, and full file name including the path.

In the sample record we can see 11th field contains file path and name in it with spaces in directory name and also file name, and all the fields are also delimited with spaces naturally.

I used:

HTML Code:
find /home/arun -type f -name "*.txt*" -mtime +90  -ls 2>/dev/null | awk '{print $5","$7","$8,$9,$10","$11} 
inorder to print 11th field (with space) but i am getting

arun1,93315072,Aug 23 06:44,/home/arun/my
arun1,93315072,Aug 23 06:44,/home/arun/myown/file
you can see 11th field is cut down since it has space... i used \"$11\" also in awk but not helping me.

I am expecting the output like below:

HTML Code:
arun1,93315072,Aug 23 06:44,/home/arun/my own/file_name.txt
arun1,93315072,Aug 23 06:44,/home/arun/myown/file name2.txt
Please help.

Thanks in advance!
# 2  
Old 01-10-2012
Instead of printing required fields, why not delete the ones not required?

Code:
awk '{$1=$2=$3=$4=""; print}'

# 3  
Old 01-10-2012
That worked!!!! So simple opposite logic... Nice.

However i wanted my output delimited by comma character.
# 4  
Old 01-10-2012
Code:
$ nawk '{printf("%s,",$5);for(i=7;i<=10;i++){printf("%s,",$i)}for(i=11;i<NF;i++){printf("%s ",$i)}printf("%s\n",$NF)}' test.txt
arun1,93315072,Aug,23,06:44,/home/arun/my own/file_name.txt
arun1,93315072,Aug,23,06:44,/home/arun/myown/file name2.txt

# 5  
Old 01-11-2012
To just answer you intitial question.

The input lines contain 12 fields instead of 11 . awk will read any space(s) as a delimiter between fields. The fact that we humans interpret a space differently because we know how to interpret the lines is not relevant to awk.

Code:
find /home/arun -type f -name "*.txt*" -mtime +90  -ls 2>/dev/null | awk '{print $5","$7","$8,$9,$10","$11" "$12}

# 6  
Old 01-11-2012
Thanks a lot!

It worked perfectly. I am trying to manipulate few more. This really helped a lot!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find File with space

Hello All, I have path /allcode/mainld/process/recenttmp where I get many type of file from other platforms. so in UNIX I need to process all file present in this location. but I don't want to process files with the space and delete them. Please provide your suggestion. (7 Replies)
Discussion started by: kumar30213
7 Replies

2. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

3. UNIX for Dummies Questions & Answers

Awk/sed to play on calender

Hello Awk'inas/Sed'ers; This is keep ringing on my mind for a while, onto play in calender with awk or sed :cool:. Given a date, month and Year would like to find out the day corresponding to it. Am still a noob on awk and sed, hence would like to learn it from your responses. Here it is;... (11 Replies)
Discussion started by: sathyaonnuix
11 Replies

4. Solaris

How to find used space on RAW device?

Hi, I'm trying to find out how to see used space on RAW device. I tried with prtvtoc -f RAWdevice but for 3 different device I'm getting the same FREE_SIZE which look a bit impossible. root@zg8cscfb1> prtvtoc -f /dev/md/redodg/rdsk/d300 FREE_START=0 FREE_SIZE=20352 FREE_COUNT=1 FREE_PART=... (2 Replies)
Discussion started by: MarioT
2 Replies

5. Red Hat

Help to Find out Available disk space

I need to find available disk space for /home. $ df /home Filesystem 1K-blocks Used Available Use% Mounted on /dev/mahhh/VolGroup11-LogVol00 32281452 45028 26034172 15% / $df /home |tail -1| awk '{print $4}' 15% The above result shows the... (5 Replies)
Discussion started by: Anu_1
5 Replies

6. Shell Programming and Scripting

find file with space and cksum

find . -type f | xargs cksum this command is failing for the files which has a space in between them any quick solution ? preferably one liner (2 Replies)
Discussion started by: reldb
2 Replies

7. Shell Programming and Scripting

find the folder with space in name.

A solaris server with SAMBA share folder. The PC users created many folders with space on it, I want to find them out, but not list its subfolders. For example, I have below folders Copy of ABC/efg/xy sa/Test again/xyt If I use command: find . -type d |grep " " I will list 6 folders, but... (2 Replies)
Discussion started by: rdcwayx
2 Replies

8. Shell Programming and Scripting

find the free space of a particular directory

Hi Guys, I want to find the free space of a particular directory,, Regards, Magesh (3 Replies)
Discussion started by: mac4rfree
3 Replies

9. Shell Programming and Scripting

Awk to find space and tab.

Wants to print line when there exist leading or trailing space or tab in fields 2,3 and 5 The below code prints all lines in file even if they dont have leading and trailing space or tab. nawk -F"|" '{for(i=1;i<=NF;i++) {if ($i ~ "^*" || $i ~ "*$")}}1' file file Ouput required: ... (5 Replies)
Discussion started by: pinnacle
5 Replies

10. Shell Programming and Scripting

for i in `find *` breakdown since the directory name has space

hey, somebody can help me on this broken script? for i in `find . -name index.html`;do echo "$i" awk '{print $0}' $i done the path to index.html has space in it. For example, ./10 October/index.html then echo "$i" will gives two lines instead of one: ./10 October/index.html how do... (3 Replies)
Discussion started by: patiobarbecue
3 Replies
Login or Register to Ask a Question