![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to delete content in a file (delete content only) | kittusri9 | Shell Programming and Scripting | 5 | 05-15-2008 10:12 AM |
| Using the content of a file in the name of another | anriot | Shell Programming and Scripting | 2 | 09-18-2006 04:56 PM |
| transfer of specific file content to another file | mem101 | Shell Programming and Scripting | 1 | 10-18-2005 11:01 AM |
| find the same content in the file | ust | UNIX for Dummies Questions & Answers | 4 | 03-25-2005 02:55 AM |
| find filename based on file content | kollerj | UNIX for Dummies Questions & Answers | 4 | 06-02-2001 10:31 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
find content from a file
root 0 0 5 0 11/09/07 08:18
root 0 0 6 0 11/09/07 08:56 root 0 0 7 0 11/22/07 11:09 user1 0 0 8 0 11/08/07 15:58 user2 0 0 9 0 11/30/07 08:37 user3 0 0 10 0 11/30/07 08:56 root 0 0 11 0 11/30/07 08:58 test user4 0 0 12 0 11/30/07 09:02 user5 0 0 13 0 11/30/07 09:34 root 0 0 14 0 11/30/07 09:11 user6 0 0 15 0 11/30/07 09:26 user6 0 0 15 0 11/30/07 09 : 26 root 0 0 16 0 11/30/07 09:28 I have the above file that have many lines , I would like to find some content in the file and output to another file with the below condition as below format . 1. do not have the word root 2. only show column 1 , 3 & 6 3. add a line no. to each row 4. do not show the duplicate line ( as above , user6 is duplicate , then only show ONE time in the new output. the output should be as below . 1 user1 0 11/08/07 2 user2 0 11/30/07 3 user3 0 11/30/07 4 user4 0 11/30/07 5 user5 0 11/30/07 6 user6 0 11/30/07 can advise what can i do ? thx |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Keeping in mind your comment about removing duplicates is ambiguous (do you mean only show one user6 per day or only one user6 - if so, which one?), here's a guess:
Code:
grep -v 'root' thefile | sort -u | awk '{ print NR,$1,$3,$6 }'
|
|
#3
|
|||
|
|||
|
Your requirement and the desired output is little different
only show column 1 , 3 & 6 then u must get 'test' in your output!! This is the same line copied from smiling dragon, i have just introduced a check before printing. grep -v 'root' sed.sh | sort -u | awk '{ if(user != $1){print NR,$1,$3,$6} ;user=$1 }' RUV |
|
#4
|
|||
|
|||
|
awk
Hi,
This one should be ok. Code:
sed '/root/d' filename | awk 'NF>=2' | sed 's/ : /:/' |sort -u | uniq -u | awk 'NF>=2 {print NR,$1,$3,$6}'
|
|
#5
|
|||
|
|||
|
How about a method that uses more shell functionality:
Code:
lineno=0
ulast=blah
sort -u myfile | while read s
do
set -- $s
case $1 in
$ulast) continue;;
user*) ;;
*) continue;;
esac
let lineno=lineno+1
echo $lineno $1 $3 $6
ulast=$1
done
|
|
#6
|
|||
|
|||
|
Hi,
I have a very similar requirement. I'm storing the passwords in a flat file, when ever the user updates the password, I'm planning to write the new password along with some other values and delete the old one. I thought of doing it using "grep -v". Can anybody help me out how to pass a variable from C program to unix command. In my previous post, I got a reply from bakunin saying to use sprintf(). I tried the below code. Code: main() { char v_unix[10]; sprintf(v_unix,"%s",argv[1]); system("cat filename | grep -v v_test > filename2"); } This didn't work. Help me to accomplish this. Thanks & Regards, Venkatesh. |
|
#7
|
|||
|
|||
|
Quote:
this script is quite useful , the output as below, 1 user1 0 11/08/07 2 user2 0 11/30/07 3 user3 0 11/30/07 4 user4 0 11/30/07 5 user5 0 11/30/07 6 user6 0 11/30/07 7 user100 0 11/30/07 8 user1222 0 11/30/07 but if I want the output is more tidy as below , can advise what can i do ? 1 user1 0 11/08/07 2 user2 0 11/30/07 3 user3 0 11/30/07 4 user4 0 11/30/07 5 user5 0 11/30/07 6 user6 0 11/30/07 7 user100 0 11/30/07 8 user1222 0 11/30/07 Last edited by ust; 11-30-2007 at 09:44 PM. |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|