extract columns from command output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract columns from command output
# 1  
Old 07-05-2009
extract columns from command output

I need to extract information (for example, file owner, directory path, etc). However, the code below does not work? What is wrong?

Code:
find /usr/local/www/apache22/data/dev/chown_test -ls
 for i in *
  do
    cut -f 1,2    "$i" | echo
  done

# 2  
Old 07-05-2009
use awk to select required fields..
Code:
find . -name "*.txt" -ls|awk '{print $5" "$NF}'

# 3  
Old 07-05-2009
Quote:
Originally Posted by montana24
I need to extract information (for example, file owner, directory path, etc). However, the code below does not work? What is wrong?

Code:
find /usr/local/www/apache22/data/dev/chown_test -ls
 for i in *
  do
    cut -f 1,2    "$i" | echo
  done

small change

Code:
find /dir/ -ls  | while read line
do
echo $line | awk '{ print $5, $1 }'
done

# 4  
Old 07-06-2009
Thanks

---------- Post updated at 10:08 PM ---------- Previous update was at 08:17 PM ----------

How do I assign that to a variable (eg. file owner)?

---------- Post updated at 10:36 PM ---------- Previous update was at 10:08 PM ----------


Something like this:
Code:
find /usr/local/www/apache22/data/dev/chown_test -ls  | while read line
  do
    owner={echo $line | awk '{ print $5}'}
    echo $owner
  done



---------- Post updated at 10:49 PM ---------- Previous update was at 10:36 PM ----------

Fixed, forgot the dollar sign and another brace type
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

2. Shell Programming and Scripting

Command to extract all columns except the last few from a txt file

hello, i have publicly available txt file with little less than 300000 rows. i want to extract from column 1 to column 218 and save it in another text file. i use the cut command but the file is saved with multiple rows from the source file onto a single row in the destination. basically it is... (6 Replies)
Discussion started by: madrazzii
6 Replies

3. Shell Programming and Scripting

Extract particular number from the command output

Hi Folks, I want to use particular number as a variable output..Please find the below for scenario... Example 1:- Below output i want to use secondary group 9003 as a variable output $ id -a |awk -NF '{print $3}' groups=99(local),9003(testadmin) Else I want to use 2006 as a... (8 Replies)
Discussion started by: susindram
8 Replies

4. Shell Programming and Scripting

Extract several columns with few rows

Hello, I want to extract several columns and rows from a huge tab delimited file for example: I want to print from from column 3 to 68 till row number 30. I have tried using cut command but it was extracting whole 3rd and 68th column. Please suggest a solution. Ryan (8 Replies)
Discussion started by: ryan9011
8 Replies

5. Shell Programming and Scripting

Extract the uptime from the output of the uptime command

Hi! I want to extract the uptime from the output of the uptime command. The output: 11:53 up 3:02, 2 users, load averages: 0,32 0,34 0,43 I just need the "3:02" part. How can I do this? Dirk (6 Replies)
Discussion started by: Dirk Einecke
6 Replies

6. Shell Programming and Scripting

Single command for add 2 columns and remove 2 columns in unix/performance tuning

Hi all, I have created a script which adding two columns and removing two columns for all files. Filename: Cust_information_1200_201010.txt Source Data: "1","Cust information","123","106001","street","1-203 high street" "1","Cust information","124","105001","street","1-203 high street" ... (0 Replies)
Discussion started by: onesuri
0 Replies

7. Shell Programming and Scripting

Extract header from top command output

hi, I want to extract and save the cpu(s) information from top command output, but individual cpu statistics separately on a multi-processor machine. In command line, top will show this statistics when we press the switch "1". any ideas? thanks, meharo (3 Replies)
Discussion started by: meharo
3 Replies

8. Shell Programming and Scripting

Extract Columns from file

Hi All, Could you please help me with following: I have to parse a .csv file. For example: If the csv file contains 3 columns, then i have to print the column names. The field separator is (comma). example.csv (contains 2 lines as follows) This is,a test file, for validation... (2 Replies)
Discussion started by: vfrg
2 Replies

9. Shell Programming and Scripting

Help, need to extract columns from file

I have huge fixed width, text file in unix box and I need to extract columns found between the width 105 and 200 and output it to a new file. Can anyone tell me how to extract it? Thanks for your help. (1 Reply)
Discussion started by: kiran2k
1 Replies

10. Shell Programming and Scripting

Extract text in 2 columns of output file.

Hello!! I have the text file with following format... --SubTotal-----------------------------------0--161---------------44---13739369-67--- --SubTotal-----------------------------------0--147---------------0----49643---1----... (2 Replies)
Discussion started by: Danish Shakil
2 Replies
Login or Register to Ask a Question