LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-23-2009, 04:45 AM   #1
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Rep: Reputation: 30
file content


I have a file , the file content is as below

$vi file
xxxxxaaa.txt
bbb.txt
xxxxxccc.txt
xxxxxddd.txt
eee.txt
xxxxxfff.txt


if I want to extract some content from this file , the condition is

1. the files are begins with xxxxx
2. remove xxxxx from the file name


so that the output should be

my desired output
============
aaa.txt
ccc.txt
ddd.txt
fff.txt

can adivse what can i do ? thx
 
Old 07-23-2009, 04:54 AM   #2
ygdrazil
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Rep: Reputation: 0
To get the lines with xxxxx:
grep "\<[xxxxx].*" file

How to emit the x's in the direct output i don't know.

ygg
 
Old 07-23-2009, 04:57 AM   #3
karamarisan
Member
 
Registered: Jul 2009
Location: Illinois, US
Distribution: Fedora 11
Posts: 374

Rep: Reputation: 55
If it's a fixed pattern, pipe the output of that grep to sed with this:
Code:
grep xxxxx | sed 's/xxxxx//'
If you need more than that, it may help to show us exactly what you're working on.
 
Old 07-23-2009, 04:58 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
sed 's/^xxxxx//g' file
use -i option if you want to actually modify the file.

A little advice, if I can: you should consider to read some good manuals about bash, sed and awk programming, since your questions (as per your previous threads) are really basic and you should put a very little effort to solve the issues. Here are some good readings to start with:
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://www.grymoire.com/Unix/Sed.html
http://www.gnu.org/software/gawk/manual/
http://www.tldp.org/LDP/abs/html/index.html (keep this as a reference guide)
 
Old 07-23-2009, 05:17 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
If I understand the OP correctly (which I most likely don't)
the sed line should be
Code:
sed -n '/^xxxx/ s/^xxxxx//gp' file
aaa.txt
ccc.txt
ddd.txt
fff.txt


Cheers,
Tink
 
Old 07-23-2009, 05:25 AM   #6
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Original Poster
Rep: Reputation: 30
thx replies ,

I tried all suggestion ,but the output is as below

aaa.txt
bbb.txt
ccc.txt
ddd.txt
eee.txt
fff.txt

but it seems not the output that I desired , can advise how to adjust to output my desired result ? thx
 
Old 07-23-2009, 05:28 AM   #7
karamarisan
Member
 
Registered: Jul 2009
Location: Illinois, US
Distribution: Fedora 11
Posts: 374

Rep: Reputation: 55
Quote:
Originally Posted by elainelaw View Post
but the output is as below
The output of what?
 
Old 07-23-2009, 05:36 AM   #8
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Original Poster
Rep: Reputation: 30
deleted
 
Old 07-23-2009, 05:43 AM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
The solution offered by Tinkster should have worked. Note the following variants:


Code:
sed -n '/^xxxx/ s/^xxxxx//gp' filename   ## Writes the output to the screen

sed -i -n '/^xxxx/ s/^xxxxx//gp' filename   ## Modifies filename in place

sed -n '/^xxxx/ s/^xxxxx//gp' filename > newfilename   ## Writes the output to a new file ("newfilename")
Did you look at the references that were suyggested?
 
Old 07-23-2009, 05:45 AM   #10
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by karamarisan View Post
The output of what?

it works , I would like to ask if it is not xxxxx , it is some special characters eg. ? / ! , what can i do ? thx
 
Old 07-23-2009, 06:05 AM   #11
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
elainelaw;

You are still not telling us which answer is working!! People have given you several suggestions---you need to tell us what you are referring to......

The general rule for using special characters in something like SED is to "escape" them using "\". Here is just one example:

Code:
Input file:
xxxxxaaa.txt
bbb.txt
xxxxxccc.txt
xxxxxddd.txt
eee.txt
/xxxxxfff.txt

sed -n /^\/xxxxx/s/\/xxxxx//gp filename
At the Grymoire site suggested earlier, there is a section on Regular Expressions--this and the SED tutorial will give you more details on escaping.
 
Old 07-23-2009, 06:15 AM   #12
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by pixellany View Post
elainelaw;

You are still not telling us which answer is working!! People have given you several suggestions---you need to tell us what you are referring to......

The general rule for using special characters in something like SED is to "escape" them using "\". Here is just one example:

Code:
Input file:
xxxxxaaa.txt
bbb.txt
xxxxxccc.txt
xxxxxddd.txt
eee.txt
/xxxxxfff.txt

sed -n /^\/xxxxx/s/\/xxxxx//gp filename
At the Grymoire site suggested earlier, there is a section on Regular Expressions--this and the SED tutorial will give you more details on escaping.
thx

your program works for me . really thx a lot.
 
  


Reply



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 to create a new file including content from reading another file !? silverhand Programming 2 10-06-2007 04:33 PM
Show file Content on File Select HTML stranger_6_7 Linux - General 4 09-24-2007 11:52 PM
delete file-content ovince Programming 6 04-17-2007 03:44 AM
changing the content of file in spec file dsubbarao Linux - Newbie 7 01-30-2007 06:41 AM
find the same content in the file ust Linux - Newbie 5 03-23-2005 03:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:01 PM.

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