How to remove the complete line?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove the complete line?
# 1  
Old 03-12-2014
Display How to remove the complete line?


This is my first post in this site

I have the next txt file "Employee.txt" with the next data
ID Name      Department Salary
1  Alejandro IT                1000
2  Alan         HR              3000
3  Lupe        IT                2500
4  Lili           Desing        1500

i need to create a script in Unix, the user has to provide the Id to remove from the file.

For example, if the use type id=3, then i have to remove the complete line from the file,

ID Name      Department Salary
1  Alejandro IT               1000
2  Alan         HR             3000
4  Lili           Desing        1500

i hope you can help me, thank you and regards

Last edited by vbe; 03-12-2014 at 02:43 PM..
# 2  
Old 03-12-2014
egrep -v "^3 " <filename>

when you create your script and use a var name of id, by example, it would be something like...

id=${1}   #if id is passed as argument 1
egrep -v "^${id} " <filename>

# 3  
Old 03-12-2014
just to be a little more careful

egrep -w -v "^3" <filename>

would be little more safer. I do see a space/tab in the above regex, but a -w will ensure you are deleting like that as your id as the first 'word'
# 4  
Old 03-12-2014
The question sounds like a homework assignment.

Also looks like OP is interested in a shell script not any utility.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print the complete line based on position as input

Hi , I have a text file like below abcd2223232321212121324343 asdsfffhfgfgfhgfhghghghghghgh dfdfdfgfghfgfgfgfgfgghghghghgh dfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdf 1234567890sasasasfdfbffghffhf abcd222323232121212abcdsds in the above file i need to grep and print the lines if 14th to 18th... (4 Replies)
Discussion started by: aravindj80
4 Replies

2. UNIX for Dummies Questions & Answers

Read complete line

Hello all, I have following line and want to search the exact match in text file. 30 6 * * * /data/abc/abc.ksh -f xya.sql -xyz@email -x -c -g I have tried it many ways like grep -W ,sed,etc.... but could not find the solution. The above line i am storing it in one variable called... (4 Replies)
Discussion started by: anyera
4 Replies

3. UNIX for Dummies Questions & Answers

Can grep command return word instead of complete line

Hi Is there any way GREP command can return word and not complete line. My file has following data: Hello Everyone I am NitinrajSrivastava Hi Friends Welcome VrajSrivastava I am using grep 'raj' which is returning me complete line.However I want only the word having keyword 'raj'. Required... (11 Replies)
Discussion started by: dashing201
11 Replies

4. Shell Programming and Scripting

Reading complete line after spaces

Hi, I am reading data from a variable which has spaces in it. I want to get the data after first space, i.e. if my data line is "My Name is Ashish...", I want the data returned as "Name is Ashish". I am using #!/bin/sh shell. Please help me with the code to read the complete data after first... (8 Replies)
Discussion started by: gupt_ash
8 Replies

5. Shell Programming and Scripting

Split a line on positions before reading complete line

Hi, I want to split before reading the complete line as the line is very big and its throwing out of memory. can you suggest. when i say #cat $inputFile | while read eachLine and use the eachLine to split its throwing out of memory as the line size is more than 10000000 characters. Can you... (1 Reply)
Discussion started by: vijaykrc
1 Replies

6. UNIX for Dummies Questions & Answers

BASH complete-filename & menu-complete together

Hi, Does anyone know how to make BASH provide a list of possible completions on the first tab, and then start cycling through the possibilites on the next tab? Right now this is what I have in my .bashrc: bind "set show-all-if-ambiguous on" bind \\C-o:menu-complete This allows... (0 Replies)
Discussion started by: Mithu
0 Replies

7. UNIX for Advanced & Expert Users

Delete a word and complete line

Hi Canone please provide me solution how can achieve the result below: File1.txt $ sweet appleŁ1 scotish green $ This is a test1 $ sweet mangoŁ2 asia yellow $ This is a test 2 $ sweet apple red (there is no pound symbol here) germany green (1 Reply)
Discussion started by: Aejaz
1 Replies

8. UNIX for Dummies Questions & Answers

Using the Esc key to complete command line typing

Dear Techs, In the past on a different box (HP) I use to be able to complete something I was typing by entering a portion of the filename in the pwd and I would hit the Esc key and it would match the rest of the filename. I did this without understanding how it was setup. Now I am on a new... (1 Reply)
Discussion started by: jxh461
1 Replies

9. UNIX for Advanced & Expert Users

ls -R command but need complete path name on each line

Can anyone help me with the following: I need to traverse subdirectories to create a list of files with the pathname. For example, here's what I get with a simple ls -alR command: /MAIN/data/30007390 dte2>>ls -alR .: total 2 drwxrwx--- 4 ecfadmin staff 96 Oct 24 18:35 . ... (2 Replies)
Discussion started by: condor4-2
2 Replies
Login or Register to Ask a Question

Featured Tech Videos