Hi,
I have a file with below format
myfile.txt
aa
aa1
aa2
qq
aa4
ghs
aa6
bbc
gdf
I m looking to create a file where lines begins with aa.
myfile1.txt
aa
aa1
aa2
aa4
aa6
Regards,
Litu
Hi,
I have a file with below format
myfile.txt
aa
aa1
aa2
qq
aa4
ghs
aa6
bbc
gdf
I m looking to create a file where lines begins with aa.
myfile1.txt
aa
aa1
aa2
aa4
aa6
Regards,
Litu
What have yuo tried so far?
cat /myfile.txt | awk '$1 ~ /^ aa*/' > /mynew.txt
---------- Post updated at 08:17 PM ---------- Previous update was at 08:13 PM ----------
awk '/aa/' /myfile.txt > newfile.txt
this seems to work. However i am looking for something without use of awk command.
Hello Litu,
awk
can read the file so there is no need to add cat
command there. You have got UUCA award Useless Use of Cat Award
Also you can remove starting space in following /^aa/
then you will get the correct output.
EDIT: Changed aa*
to aa
in suggestion. grep
command can help us here for same.
grep "^aa" filename
Output will be as follows.
aa
aa1
aa2
aa4
aa6
Thanks,
R. Singh
Try:
grep '^aa' file > newfile
----
That should be
/^aa/