Filtering data from text to csv


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filtering data from text to csv
# 1  
Old 09-10-2013
Filtering data from text to csv

Hello,

Is there a way to filerter data from a text file as shown below to a Column

e.g.

hostname nfsmount as two separate column. Currently I could get hostname and the mount is appearing below.. using this script
Code:
#! /bin/bash

for i in `cat fqdn.txt`
do
echo "$i ............ " >> fstab.txt
ssh username@$i "cat /etc/fstab |column -t | grep 'bur-filer*'" >> fstab.t    xt
done


Code:
hostname.host1.com ............ 
bur-filer2:/vol/vol1    /mnt/bur-filer2/vol1    nfs     rw,defaults     0

hostname.host2.com ............ 
bur-filer2:/vol/vol1    /mnt/bur-filer2/vol1    nfs     rw,defaults     0

Thank You

Last edited by joeyg; 09-10-2013 at 03:33 PM.. Reason: Please wrap commands and data inside CodeTags
# 2  
Old 09-10-2013
You have shown the data you don't want, but haven't shown the data you do want, so I don't understand what you want your output to look like.

You can simplify your code as such:

Code:
#! /bin/bash

while read i
do
        echo "$i ............ "
        ssh -n username@$i "< /etc/fstab column -t | grep 'bur-filer.*'"
done < fqdn.txt > fstab.txt

# 3  
Old 09-10-2013
Thank you for your reply.

I am looking for the output like this

Hostname Mount Points
hostname.host1.com bur-filer2:/vol/vol1 /mnt/bur-filer2/vol1
hostname.host2.com bur-filer2:/vol/vol1 /mnt/bur-filer2/vol1

Instead of showing like this.

hostname.host1.com ............
bur-filer2:/vol/vol1 /mnt/bur-filer2/vol1 nfs rw,defaults 0

hostname.host2.com ............
bur-filer2:/vol/vol1 /mnt/bur-filer2/vol1 nfs rw,defaults 0

Appreciate your help

Thank you
# 4  
Old 09-10-2013
If your system allows for it, try to suppress echo's new line char:
Code:
echo -n "$i"

or use printf omitting the \n in the format string.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Filtering records of a csv file based on a value of a column

Hi, I tried filtering the records in a csv file using "awk" command listed below. awk -F"~" '$4 ~ /Active/{print }' inputfile > outputfile The output always has all the entries. The same command worked for different users from one of the forum links. content of file I was... (3 Replies)
Discussion started by: sunilmudikonda
3 Replies

2. Shell Programming and Scripting

Need help with csv filtering

Hello everyone, i am stuck with a task i was meant to do so i came here. So i have a .csv file which structure is : year;temperature;precipitation 2012;32;483 2006;28;517 ... I want to note that it is in fact ";" not a space, which a new file named <old-name>-new.txt, the first line must ... (2 Replies)
Discussion started by: Needhelp123
2 Replies

3. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

4. Shell Programming and Scripting

Read multiple text files and copy data to csv

hi i need to extract lines from multiple files to a csv file. for example, i have these 3 files file1.txt date:29dec1980 caller:91245824255 called:8127766 file2.txt date:11apr2014 caller:9155584558 called:8115478 file3.txt date:25jun2015 caller:445225552 called:8117485 (30 Replies)
Discussion started by: lp.descamps
30 Replies

5. Shell Programming and Scripting

Converting data for text file to csv

Gents Using the script attached (raw2csv). i use to create the file .csv.. The input file is called 201.raw. Kindly can you check if there is easy way to do it. The script works fine but takes a lot time to process Thanks for your help (8 Replies)
Discussion started by: jiam912
8 Replies

6. Shell Programming and Scripting

Filtering out lines in a .csv file

Hi Guys, Would need your expert help with the following situation.. I have a comma seperated .csv file, with a header row and data as follows H1,H2,H3,H4,H5..... (header row) 0,0,0,0,0,1,2.... (data rows follow) 0,0,0,0,0,0,1 ......... ......... i need a code... (10 Replies)
Discussion started by: dev.devil.1983
10 Replies

7. Shell Programming and Scripting

Reading 2 CSV files and filtering data based on group

I have two CSV files in the following format: First file: GroupID, PID:TID, IP, Port Sample data: 0,1000:11,127.0.0.1,445 0,-1:-1,127.0.0.1,800 1,1000:11,127.0.0.1,445 1,-1:-1,127.0.0.1,900 2,1000:11,127.0.0.1,445 2,-1:-1,180.0.0.3,900 Second file: IP,Port,PID Sample data... (6 Replies)
Discussion started by: rakesh_arxmind
6 Replies

8. Shell Programming and Scripting

Text file to CSV with field data separated by blank lines

Hello, I have some data in a text file where fields are separated by blank lines. There are only 6 fields however some fields have several lines of data as I will explain. Also data in a particular field is not consistently the same size but does end on a blank line. The first field start with... (6 Replies)
Discussion started by: vestport
6 Replies

9. Shell Programming and Scripting

Help with pulling / filtering data from a .csv

Good day Gurus, I have a csv file that contains an inventory of active servers. This csv file contains a well over a hundred systems (IBM, SUN, HP). It also contains those systems details. See below for an example hostA,invver,1.02,20100430 hostA,date,08/30/2010,06:18 hostA,use,"Unknown... (4 Replies)
Discussion started by: LuffyDMonkey
4 Replies

10. Shell Programming and Scripting

Exporting text file data to csv

Could any one help me in basic shell script to export text file data to csv. I need to export only particular data from text file to csv column. I am a newbie to UNIX could anyone help me with sample script code (3 Replies)
Discussion started by: l_jayakumar
3 Replies
Login or Register to Ask a Question