LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   can someone help me write a short script? (https://www.linuxquestions.org/questions/linux-newbie-8/can-someone-help-me-write-a-short-script-425222/)

knoxville217 03-15-2006 08:41 PM

can someone help me write a short script?
 
I was hoping to write a short script using 'awk' or 'bash scripting' to remove two types of strings from a file: the date, and the full directory of the item (for windows). Also, as you can tell from the use of quotes, I am quite the n00b, and simply guesssed that these might be the tools I might use to remedy this problem. So anyway, back to the problem: instead of
Code:

This Fire Franz Ferdinand 1/02/03 C:\Music\This Fire
the not yet written script would shorten it to
Code:

This Fire Franz Ferdinand
.

pixellany 03-15-2006 09:33 PM

Let's see--you want to use Linux tools to manipulate Windows files.....Trouble lies ahead.
First, you need read/write access to the Windows filesystem--If NTFS, then Linux is not very good at that. Are you going to put the files into your Linux filesystem?

If you are simply editing multiple lines which have the same overall pattern, then sed will do it.

In your example--is this a line from a file?

More details, more help....

knoxville217 03-15-2006 09:45 PM

Ok, it is a text file, and it is already on my ext3 partition, so no need to worry about windows :).

Here is another example to make it clearer:
Code:

Numb      Linkin Park      1/20/03    C:/Music/Linkin Park/Numb
Goodbye  SR-71            1/20/03    C:/Music/SR-71/Goodbye

I want to remove the date/directory thing, so I would get:
Code:

Numb      Linkin Park
Goodbye  SR-71


nadroj 03-15-2006 10:40 PM

im assuming its a plain text file, with all fields seperated by tabs. if thats the case, this should work:
Code:

cut -f1,2 nameoffile
by default, this will print to the screen. you can append a '> ' character to the end of that command, along with a filename, and it will send the output to that file instead of to the screen.

muha 03-16-2006 03:16 AM

when you want to use awk try this:
Code:

$ cat aa.txt
Numb      Linkin Park      1/20/03    C:/Music/Linkin Park/Numb
Goodbye  SR-71            1/20/03    C:/Music/SR-71/Goodbye
$ awk '{ print $1,$2 }' aa.txt
Numb Linkin
Goodbye SR-71



All times are GMT -5. The time now is 11:28 PM.