Need help with csv filtering


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with csv filtering
# 1  
Old 12-27-2017
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 :

Code:
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

contain year and temperature separated by a space, also to
transfer the rows in which year interval is 2007-2013 and
temperature interval is 28-35. I am stuck at this problem
for several hours, i know how to solve the problem with awk
if there were more columns, not 1. Sorry for bad English.
Moderator's Comments:
Mod Comment Please do not use COLOR and FONT tags on every line when you post a comment.

Please use CODE tags when displaying sample input, sample output, and code segments.

Last edited by Don Cragun; 12-27-2017 at 05:44 PM.. Reason: Add CODE and ICODE tags; get rid of COLOR and FONT tags.
# 2  
Old 12-27-2017
Quote:
Originally Posted by Needhelp123
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 :

Code:
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

contain year and temperature separated by a space, also to
transfer the rows in which year interval is 2007-2013 and
temperature interval is 28-35. I am stuck at this problem
for several hours, i know how to solve the problem with awk
if there were more columns, not 1. Sorry for bad English.
Moderator's Comments:
Mod Comment Please do not use COLOR and FONT tags on every line when you post a comment.

Please use CODE tags when displaying sample input, sample output, and code segments.
Hi Needhelp123,
Welcome to the UNIX & Linux Forums.

Is this a homework assignment? Homework and coursework questions can only be posted in the Homework & Coursework subforum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

If this is not a homework assignment, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

If this is not a homework assignment, please also tell us what operating system you're using and what shell you're using. (The capabilities provided by awk vary somewhat from system to system and it wastes our time and yours if we make suggestions that won't work on your system.)

Also please give us a sample input file (including its filename) and the output you hope to produce from that input file (including its filename). It would be a good idea to have sample that input would test all of the conditions your code is supposed to use to determine whether or not a line of input should be copied to the output. (And, remember to surround the sample input and output with CODE tags.)
# 3  
Old 12-28-2017
Quote:
Originally Posted by Needhelp123
i know how to solve the problem with awk
if there were more columns, not 1.
There is not one column, there are three. Note that with awk, the separator can be any string. It doesn't need to be a string of spaces. See the -F option of awk.
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

Match columns from two csv files and update field in one of the csv file

Hi, I have a file of csv data, which looks like this: file1: 1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628 2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies

3. Shell Programming and Scripting

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 #! /bin/bash for i in `cat fqdn.txt` do echo "$i ............ " >>... (3 Replies)
Discussion started by: Cy Pqa
3 Replies

4. 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

5. 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

6. Shell Programming and Scripting

Perl search csv fileA where two strings exist on another csv fileB

Hi I have two csv files, with the following formats: FileA.log: Application, This occured blah Application, That occured blah Application, Also this AnotherLog, Bob did this AnotherLog, Dave did that FileB.log: Uk, London, Application, datetime, LaterDateTime, Today it had'nt... (8 Replies)
Discussion started by: PerlNewbRP
8 Replies

7. Shell Programming and Scripting

CSV to SQL insert: Awk for strings with multiple lines in csv

Hi Fellows, I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem: I have csv files in the following pipe-delimited format: Column1|Column2|Column3|Column4|NEWLINE Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies

8. 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

9. Shell Programming and Scripting

2 problems: Mailing CSV file / parsing CSV for display

I have been trying to find a good solution for this seemingly simple task for 2 days, and I'm giving up and posting a thread. I hope someone can help me out! I'm on HPUX, using sqlplus, mailx, awk, have some other tools available, but can't install stuff that isn't already in place (without a... (6 Replies)
Discussion started by: soldstatic
6 Replies

10. Shell Programming and Scripting

Need to compare two csv files values and write into another csv file

Hi all, Am new to scripting. So i just need your ideas to help me out. Here goes my requirement. I have two csv files 1.csv 2.csv abc,1.24 abc,1 def,2.13 def,1 I need to compare the first column of 1.csv with 2.csv and if matches then need to compare... (2 Replies)
Discussion started by: chinnahyd
2 Replies
Login or Register to Ask a Question