LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-23-2011, 11:30 AM   #31
Vodkaholic1983
Member
 
Registered: May 2010
Distribution: Windows / Debian
Posts: 163

Original Poster
Rep: Reputation: 0

Quote:
Originally Posted by MTK358 View Post
If you want the result in a different file:

Code:
sed -r 'expression' source_file > dest_file
If you want the original file to be overwritten with the new data:

Code:
sed -i -r 'expression' file
Hopefully you can figure it out now.

EDIT: Also, you shold NEVER use ls output in a script. It's meant for human reading only.

Use this instead to loop over files in a directory:

Code:
for FILE in *
do
    # stuff
done
Ok am mega confused now sorry
The guy in this post made that code I posted above
It was for renaming alot files and it worked just fine

Only the start of the file names have changed everything else Ive wrote in this thread still is the same

Am really really new to linux and you say never use output, I have no idea what your talking about sorry :C
Thanks for the help btw
 
Old 04-23-2011, 11:33 AM   #32
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by Vodkaholic1983 View Post
m really really new to linux and you say never use output, I have no idea what your talking about sorry :C
I didn't say "never use output", I said "never use the output of the ls command for anything but reading by humans.".

Maybe you should check out the LinuxCommand tutorial (there's a link to it in my sig). It has a very nice section on scripting.
 
Old 04-23-2011, 11:36 AM   #33
Vodkaholic1983
Member
 
Registered: May 2010
Distribution: Windows / Debian
Posts: 163

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MTK358 View Post
I didn't say "never use output", I said "never use the output of the ls command for anything but reading by humans.".

Maybe you should check out the LinuxCommand tutorial (there's a link to it in my sig). It has a very nice section on scripting.
I thought it might of been just a simple change in that .sh file was all

Thanks I'll have a look when work is over
 
Old 04-23-2011, 11:55 AM   #34
Vodkaholic1983
Member
 
Registered: May 2010
Distribution: Windows / Debian
Posts: 163

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MTK358 View Post
Code:
sed -r 's/[a-zA-Z0-9]+\.[a-z]+[ \t]+[a-zA-Z0-9]+\.[a-z]+[ \t]+-[ \t]+[0-9]+[ \t]+-[ \t]+(.*)/\1/'
Also I tryed this and it did nothing apart from in putty it went to the next line
plus I had to restart putty as I couldn't type again
 
Old 04-23-2011, 12:56 PM   #35
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by Vodkaholic1983 View Post
Also I tryed this and it did nothing apart from in putty it went to the next line
plus I had to restart putty as I couldn't type again
How do you think that will automatically do what you want without specifying the input and output files?

(BTW, press Ctrl+C to kill it. You don't need to restart the terminal).

Did you read the LinuxCommand tutorial, or at least try to learn or understand anything?
 
Old 04-23-2011, 12:57 PM   #36
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by Vodkaholic1983 View Post
I thought it might of been just a simple change in that .sh file was all
Actually, it is a simple change in the .sh file.
 
Old 04-23-2011, 01:53 PM   #37
Vodkaholic1983
Member
 
Registered: May 2010
Distribution: Windows / Debian
Posts: 163

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MTK358 View Post
(BTW, press Ctrl+C to kill it. You don't need to restart the terminal).
Did you read the LinuxCommand tutorial, or at least try to learn or understand anything?
Thanks for that
I did say "Thanks I'll have a look when work is over" It was just a quick test
 
Old 04-23-2011, 02:09 PM   #38
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
If I understand your problem correctly, then this should work:

Code:
#!/bin/bash

find $PWD -type d | grep -v "^${PWD}$" | \
while read directory
do
  for file in "$directory"/*
  do
    mv -n "$file" "$(echo "$file" | sed -r 's/[a-zA-Z0-9]+\.[a-z]+[ \t]+[a-zA-Z0-9]+\.[a-z]+[ \t]+-[ \t]+[0-9]+[ \t]+-[ \t]+(.*)/\1/')"
  done
done
 
Old 04-24-2011, 07:45 AM   #39
Vodkaholic1983
Member
 
Registered: May 2010
Distribution: Windows / Debian
Posts: 163

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MTK358 View Post
If I understand your problem correctly, then this should work:

Code:
#!/bin/bash

find $PWD -type d | grep -v "^${PWD}$" | \
while read directory
do
  for file in "$directory"/*
  do
    mv -n "$file" "$(echo "$file" | sed -r 's/[a-zA-Z0-9]+\.[a-z]+[ \t]+[a-zA-Z0-9]+\.[a-z]+[ \t]+-[ \t]+[0-9]+[ \t]+-[ \t]+(.*)/\1/')"
  done
done
Thanks very much that worked just fine! Ive also bookmarked that site thanks for that too!
 
  


Reply

Tags
file, trim


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
I/O problem -- dd if=/dev/zero of=bf bs=8k count=500000 fengzhong_77 Linux - Newbie 1 11-04-2009 06:28 PM
How can I get the edquota file's name? snowball0916 Ubuntu 10 07-17-2009 10:31 AM
How to get a file's symlinks jfrankman Linux - Newbie 10 11-02-2006 12:45 PM
file's extension??? amanjsingh Linux - Newbie 2 04-17-2004 10:22 AM


All times are GMT -5. The time now is 01:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration