Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 04-22-2004, 06:55 AM   #1
LQ Newbie
Registered: Apr 2004
Posts: 3

Rep: Reputation: 0
Removing lines from file


I'm working on a script where I need to remove some lines from a semi-color seperated file - example;
Car;Ford Taurus;Red
Car;Ferrari 360;Yellow

Thats a silly example I know

What I want to do is remove all lines where the first field (I should mention I was hoping on using awk) matches stored in a variable, let's call it 'TYPE'.
I also want to be able to remove entries from field 2 based on a used typed regexp, so I would love to have this so flexible that it will cater for both scenarios.

#for line in $(cat $catalogue_file | awk -F";" '{print $1}' | grep -v $volume_name)
    echo $line >> after.db
That is the way I've envisioned it initially.. it works sort of, the problem of course is that it only writes the first field to the temp file. But I need the entire line.

I'm sure my code is a really stupid approach, so feel free to make fun :P

Thanks in avance!
Old 04-22-2004, 07:24 AM   #2
LQ Newbie
Registered: Apr 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Ok, I've found a working solution for the first case, where I simply want to match against a user typed value. I haven't yet solved the regexp case.

Please comment on this, and if you got a better solution let me know!

awk -v vol="$volume_name" -F";" '$1 != vol { print $0 }' $catalogue_file >> newdb.db
Old 04-22-2004, 07:34 AM   #3
LQ Newbie
Registered: Apr 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Seems like I just solved RE case too

awk -v re="$pattern" -F";" '$2 !~ re { print $0 }' $catalogue_file >>
Again, please comment if you spot any potential problems or have other solutions.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How can I sort the lines in a file? windhair Linux - Software 2 11-17-2005 09:37 AM
removing special lines from files Prasun1 Linux - General 3 09-11-2005 06:16 AM
[bash] removing or editing lines in file Erhnam Programming 12 03-15-2005 08:25 AM
Removing duplicate lines with sed tireseas Programming 10 01-12-2005 04:27 AM
removing lines from file script iluvatar Programming 9 08-20-2004 06:49 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:50 PM.

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