Visit Our UNIX and Linux User Community


How to format output of command?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to format output of command?
# 1  
Old 09-18-2013
How to format output of command?

Hi how do you change the format of the output of
Code:
ls -lt -c -R $HOME | sed /^total/d

From:
Code:
/home/pikamon/Desktop:
-rwxr-xr-x 1 pikamon pikamon 35 Sep 18 14:25 fileModified.sh
-rwxr-xr-x 1 pikamon pikamon 87 Sep 18 14:25 fileModified.sh~

/home/darksky21/Downloads:
-rwxrw-rw- 1 pikamon pikamon 19889714 Sep 14 18:02 test.deb
-rwxrw-rw- 1 pikamon pikamon 127352 Sep 14 18:02 testing2

/home/pikamon/Documents:

/home/pikamon/Music:

To:

Code:
-rwxr-xr-x 1 pikamon pikamon 35 Sep 18 14:25 /home/pikamon/Desktop/fileModified.sh
-rwxr-xr-x 1 pikamon pikamon 87 Sep 18 14:25 /home/pikamon/Desktop/fileModified.sh~
-rwxrw-rw- 1 pikamon pikamon 19889714 Sep 14 18:02 /home/darksky21/Downloads/test.deb
-rwxrw-rw- 1 pikamon pikamon 127352 Sep 14 18:02 /home/darksky21/Downloads/testing2

using shell script. I would like to remove the path on the header and add it into the path of each directory

Last edited by Scrutinizer; 09-18-2013 at 05:00 PM.. Reason: code tags
# 2  
Old 09-18-2013
You may try the find command

Code:
find $HOME -type f -exec ls -l {} \;

or

Code:
ls -ltcR $HOME | awk '/^\// {dir=substr($0,1,length($0)-1)} /^-/{$9=dir"/"$9;print}'


Last edited by krishmaths; 09-18-2013 at 04:14 AM..
This User Gave Thanks to krishmaths For This Post:
# 3  
Old 09-18-2013
This might also be helpful to you.
Code:
ls -ltcR $HOME | grep -v "^total" | grep -v "^\/" | grep -v "^$"

# 4  
Old 09-18-2013
Whenever you find yourself doing grep | grep | grep | grep | grep, it's time to learn awk:

Code:
ls -ltcR $HOME | awk '!/^total/ && !/\// && !/^$/'

This User Gave Thanks to Corona688 For This Post:
# 5  
Old 09-18-2013
Try
Code:
ls -tlcR | awk '/^total|^$/ {next} NF==1 {D=$1} {$9=D $9; sub (":","/",$9)} 1'

# 6  
Old 09-19-2013
Thx for all the help and reply still new to all this shell command

Previous Thread | Next Thread
Test Your Knowledge in Computers #380
Difficulty: Medium
Apple's macOS (previously known as Mac OS X or OS X) is a UNIX 03 registered product.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get the output of w command in pipe delimited format

Since output of w command have variable number of columns I want to get the output in pipe delimited format. I tried export OFS="|"; w but that does not work. Any ideas? (4 Replies)
Discussion started by: Soham
4 Replies

2. Shell Programming and Scripting

Grep command output in tabular format

I have a grep command script which works fine and give the correct results but i wanted the output to be displayed in tabular format ? Is it possible to display the output in tabular format and as well direct them to some file. main script : #!/usr/bin/bash Start_Time=`date '+%m%d%y... (1 Reply)
Discussion started by: Optimus81
1 Replies

3. Shell Programming and Scripting

UNIX command output in csv format

I'm just wondering is there any way to capture the output of a unix command in a csv format. df -h gives the result of filesystem,free space,Used space, use %,mounted on. Is there a way to capture the command output and format it as comma sparated or fixed length file. (3 Replies)
Discussion started by: anita81
3 Replies

4. UNIX for Dummies Questions & Answers

UNIX command output format

how can I get the df -h command output into excel format or csv file. df -k | tr -s " " | sed 's/ /, /g' | sed '1 s/, / /g' | column -t df -h | column -t I have tried as above but the format is not right. I'm not able to load the format into a excel or a table. ... (2 Replies)
Discussion started by: anita81
2 Replies

5. Shell Programming and Scripting

Format Top and prstat command output

need help with formatting output of command top and prstat. My requirment is to remove few columns and display remaining . But when i used awk to do that the output seems to be have gone vague, mixing the column values. After using awk to print particular column the output seems to have lost... (1 Reply)
Discussion started by: NarayanaPrakash
1 Replies

6. Shell Programming and Scripting

Format output in AWK command

hi Friends , I have a file as below s.txt 1~2~~4 2~6~~7 3~8~~9 t.txt 1~2~~4 2~5~8~7 3~8~~7 header for both files is common (2 Replies)
Discussion started by: i150371485
2 Replies

7. Shell Programming and Scripting

Format output from command from variables

Hi , I have below command to that outputs from variables.. command: echo $INSTANCE $DATAB $status $TSLastBackup| awk '{printf("%-8s %-8s \t \n",$1,$2,$3,$4)}' | tee $LOGF the ouput is now: INSTANCE DATABSE BACKUP_STATUS BACKUPTIMESTAMP ------- -------- -------- ... (1 Reply)
Discussion started by: db2_usd
1 Replies

8. Shell Programming and Scripting

shell script to format command output

Hello team, I am running below command which is giving following output. bash-3.00$ ps -eo pid,pcpu,args | sort +1n | grep -i java 12 0.0 grep -i java 8804 0.0 /opt/app/ccr/home/ccr/WebSphere/AppServer/java/bin/sparcv9/java -XX:+UnlockDiag 9241 0.0... (7 Replies)
Discussion started by: coolguyamy
7 Replies

9. Shell Programming and Scripting

Help me to command to output file format.

Dear Master. Help me to command to out put. Ex log. "<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom> <txid>17251032659</txid> <authentication> <user>admin</user> <password>Amrduoi</password> </authentication> <destination> <msisdn>1111111</msisdn> ... (2 Replies)
Discussion started by: ooilinlove
2 Replies

10. Shell Programming and Scripting

Format Output with AWK command

Hi - I have a file with contents as below. 12.1 a.txt 12.1 b.txt 12.1 c.txt 13.2 a.txt 13.2 d.txt 14.3 f.txt 15.4 a.txt 15.4 b.txt 15.4 z.txt I need to print the contents like this. 12.1 a.txt <&nbsp><&nbsp><&nbsp>b.txt <&nbsp><&nbsp><&nbsp>c.txt (7 Replies)
Discussion started by: guruparan18
7 Replies

Featured Tech Videos