Removing File Entries With sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing File Entries With sed
# 1  
Old 05-24-2010
Removing File Entries With sed

Hi

When running the following sed command from the command line I am able to
remove all entries with #username from the file and redirect to another file.

Code:
sed -e 's/#.*//' -e '/^$/d' namesonly > tt

Code:
mv tt > namesonly

When I use the same command in the following script I end up with the original
entries in the namesonly file. ie nothing has been removed.


Code:
 
echo "" > f-output.log
 
USERS=$(awk -F: '{print $1}' allusers)
for U in $USERS
 
do
 
finger ${U} >> f-output.log
 
awk '/^Logi/ {a=$3} /^Last log/ {print a, $6}' f-output.log > lastlogin
 
grep -v "2009" lastlogin > lastlogin_1 ; grep -v ":" lastlogin_1 | sort | uniq > newlog_1
 
cut -d' ' -f1 newlog_1 > namesonly
 
sed -e 's/#.*//' -e '/^$/d' namesonly > tt ; mv tt namesonly

done

Is there an error with this command or something else causing the problem?

Any help appreciated.
# 2  
Old 05-24-2010
You are looping the script for each users. so make sure you append the strings in the "namesonly" file rather than overwriting it each time in the loop.
# 3  
Old 05-24-2010
Thanks for your response....append the strings in the "namesonly" file
Can you provide an example... I tried the following which didnt work.
Do I need to change elsewhere in the script

Code:
sed -e 's/#.*//' -e '/^$/d' namesonly >> tt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Removing unwanted symbols with sed

I would like produce blue, green, red, yellowfrom"blue:,*green:,*red:,*yellowI can remove the colon with echo "blue:,*green:,*red:,*yellow" | sed 's/://g'which givesblue,*green,*red,*yellowbut when I try echo "blue:,*green:,*red:,*yellow" | sed 's/://g'; 's/*//g'I get bash: s/*//g: No such... (9 Replies)
Discussion started by: Xubuntu56
9 Replies

2. Shell Programming and Scripting

Removing quotes in sed

I have a file and I want to remove quotes from the word " ` " through sed command but unable to remove I am using below command sed s/"`XYZ`"/"ZXY"/g file1.txt > file2.txt But this is not working. How can we remove "`" through sed command (2 Replies)
Discussion started by: kaushik02018
2 Replies

3. Shell Programming and Scripting

Problem removing $ using sed in script

I am trying to use the sed command to remove any character that is passed as a parameter to the script. I may want to replace any character in the file (-, =, $, space). I'm running into an issue when passing the $. This is a typical row in the file. "000000B553","--INTERNAL USE... (6 Replies)
Discussion started by: nadneb
6 Replies

4. Shell Programming and Scripting

sed removing values

Is there an easy way in sed to remove a character and values after that character? ex: blackout_10-11-2011(NODE_LEVEL) I want to remove '(' and everything after. so I will only have. blackout_10-11-2011 I can use a cut command to do this but interested in seeing how its done... (1 Reply)
Discussion started by: BeefStu
1 Replies

5. Shell Programming and Scripting

SED removing CR/LF

I have a source text file that contains something like this: <start_template> bool function( void *<var_name> ) { // Blah Blah } </start_template> Following is used to remove this template from source file. template=$(sed -n -e '/<start_template>/,/<\/start_template>/{... (4 Replies)
Discussion started by: gee22
4 Replies

6. UNIX for Dummies Questions & Answers

Need advice! Removing multiple entries in a single file!

Hello, I have a file Test.txt with 9 columns that looks like this: 1g12 A 14 19 2OAY A 326 331 AAAASA 1l7v A 68 73 1l7v A 68 73 AALAIS 1l7v A 68 73 1XVW B 72 77 AALAIS 1l7v A 68 73 1XXU A 65 70 AALAIS 1l7v A 68 73 1XXU B 65 70 AALAIS 1l7v A 68 73 1XXU C 65 70 AALAIS 1l7v A 68 73 1XXU D... (4 Replies)
Discussion started by: InfoSeeker
4 Replies

7. Shell Programming and Scripting

Removing a character using sed

Hi, I have a file with the text below. How do i remove the character "%" from the text file using sed ? Can anybody help ? 0% 68% 72% 0% 54% 33% 75% 24% 6% 59% 77% 77% 33% (6 Replies)
Discussion started by: Raynon
6 Replies

8. Shell Programming and Scripting

Removing lines with sed

Here is some code output that I have: architecture ppc cputype CPU_TYPE_POWERPC cpusubtype CPU_SUBTYPE_POWERPC_ALL offset 4096 size 184464 align 2^12 (4096) architecture ppc64 cputype CPU_TYPE_POWERPC64 cpusubtype CPU_SUBTYPE_POWERPC_ALL offset 192512 ... (5 Replies)
Discussion started by: pcwiz
5 Replies

9. Shell Programming and Scripting

Removing '." character using SED

HI All, Have some files which contains some string like, "create .<table1> as" "insert into .<table2> values", i want to replace ".<table1>" with only "<table1>", i.e removing '.' character in ksh, i have written below code but it is not removing the dot character, any help? for name... (2 Replies)
Discussion started by: arvindcgi
2 Replies

10. Shell Programming and Scripting

Removing carriage returns with sed

How do we delete all carriage returns after a particular string using sed inside a K Shell? e.g. I have a text file named file1 below: $ more file1 Group#=1 User=A Role=a1 Group#=2 User=B Role=a1 Role=b1 Group#=3 User=C Role=b1 I want the carriage returns to be delete on the... (12 Replies)
Discussion started by: stevefox
12 Replies
Login or Register to Ask a Question