LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-11-2009, 06:09 AM   #1
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Rep: Reputation: 36
Removing whiteline spaces using awk


Hello all,

I am trying to read the file names from the output of tar command.

Code:
-rw-r--r-- 1 hal9000 hal9000 133 2009-12-01 21:06 array.pl
-rw-r--r-- 1 hal9000 hal9000 372736 2009-11-19 01:18 unix/linux/perl/perlscripts/lol.pl
I'm getting the filename using awk by printing the 8th column,the result is unix/linux/perl/perlscripts/lol.pl and array.pl

If there are multiple spaces(if dir names have spaces in them) in the output for ex:

Code:
-rw-r--r-- 1 hal9000 hal9000 372736 2009-11-19 01:18 unix/linux/perl/perl scripts/my scripts for perl/lol.pl
then the printing 8th col yields only unix/linux/perl/perl. Can any one show me how to squeeze the whitespaces that come after 8th column and merge it with the 8th column? I want the final output to be

Code:
unix/linux/perl/perlscripts/myscriptsforperl/lol.pl
Thanks.
 
Old 12-11-2009, 06:13 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
awk '{for(i=1;i<=7;i++)$i=""}1'
if you mind the white spaces, remove yourself using gsub/sub.

or you can use cut

Code:
cut -d " " -f8-
 
Old 12-11-2009, 06:39 AM   #3
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Original Poster
Rep: Reputation: 36
Thanks ghosts,what i want to do here is where ever there is a whitespace in the directory name i want to squeeze.


Code:
hal9000@wsx04:~$ tar -tvf test.rar
-rw-r--r-- hal9000/hal9000         0 2009-12-11 17:57 TEST/B/lol.txt
drwxr-xr-x hal9000/hal9000         0 2009-12-11 17:57 TEST/the linux project/
-rw-r--r-- hal9000/hal9000         0 2009-12-11 17:57 TEST/the linux project/helloworld.sh
-rw-r--r-- hal9000/hal9000         0 2009-12-11 17:57 TEST/the linux project/helloworld.py
-rw-r--r-- hal9000/hal9000         0 2009-12-11 17:57 TEST/B/helloworld.txt
when i do awk -F" " '{print $6}' it prints the .txt files that is lol and helloworld,but doesnt print the .sh and .py files. Is there any way that i can print the columns that come after 5th column as one column by merging?

I tried awk '{for(i=1;i<=7;i++)$i=""}1' it prints only

Code:
project/
project/helloworld.sh
project/helloworld.py
as the output,but i wisht to print the other files as well.


Thanks.

Last edited by kdelover; 12-11-2009 at 06:48 AM.
 
Old 12-11-2009, 08:07 AM   #4
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Original Poster
Rep: Reputation: 36
ok i guess i found the solution for it
Quote:
awk -F" " '{print $1,$2,$3,$4,$6$7$8}'
printing the columns without commas is working,is there any way i can provide a range here as in print from column 6 to column 10? instead of using $6$7$8$9$10.


Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
removing white spaces in the file tucs_123 Linux - Newbie 9 01-03-2009 10:28 AM
[SOLVED] Removing lines and spaces - Formatting Text vikas027 Programming 8 10-10-2008 03:06 PM
Inserting spaces using SED/AWK ? aravindts Programming 4 09-29-2006 05:28 AM
shell programming - removing files with spaces ANU Programming 4 08-08-2006 04:42 AM
Removing spaces from string qcoder Programming 3 07-05-2004 12:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration