Question about SED cutting and renaming


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question about SED cutting and renaming
# 8  
Old 06-20-2007
That's perfect. Is there a way to dump the outfiles into a subdirectory, so they're separate from the original source files?
# 9  
Old 06-20-2007
Try this (not tested) :
Code:
awk -v dir="./extracts" '
   /^Document [0-9]/,/^==========*$/ {
      if (/^Document [0-9]/) {
         if (outfile) close(outfile);
         seq = $2;
         outfile = dir "/" FILENAME;
         sub(/\.[^.]*$/, "-" seq "&", outfile);
      }
      print $0 > outfile
   }
' *.txt

# 10  
Old 06-20-2007
perfect. Thanks so much to everybody. I've learned a lot.
# 11  
Old 06-20-2007
Although, if you have a few minutes, and if you feel like it, maybe you could you walk me through the steps so I know what it is that it's doing? Only if you have the time though...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed expression-help cutting name

Hi, I have some sample names. The regions in red are what I want to extract. AIB13-positive AIB13-blank AIB13-1116-0022999 GNX13-1521-0003532 Each of the sample names are represented as variable ${SAMPLE} within a loop. I've tried extracting the middle region with the following code... (2 Replies)
Discussion started by: jdilts
2 Replies

2. Windows & DOS: Issues & Discussions

Simple renaming question

I want to rename all fileextensions inside a folder that are called ".srt.ass" to just ".ass" My (poor code so far is): or %x in (*.srt.ass) do RENAME "*.srt.ass" "*.ass" Thanks in advance. (4 Replies)
Discussion started by: pasc
4 Replies

3. Shell Programming and Scripting

Help with renaming file using sed

Hi, I am currently updating a script, It should do the ff: rename the YYYYMMDD in mainlog.YYYYMMDD to $NEW_DATE I was ask to use sed but I am not that familiar with it. I should update the touch part with the sed. Please kindly help me with this. Thanks a lot. ... (3 Replies)
Discussion started by: joyful1213
3 Replies

4. UNIX for Dummies Questions & Answers

renaming multiple files using sed or awk one liner

hi, I have a directory "test" under which there are 3 files a.txt,b.txt and c.txt. I need to rename those files to a.pl,b.pl and c.pl respectively. is it possible to achieve this in a sed or awk one liner? i have searched but many of them are scripts. I need to do this in a one liner. I... (2 Replies)
Discussion started by: pandeesh
2 Replies

5. Shell Programming and Scripting

Renaming files with sed

Hi all, I created file like this AAb.lol AAc.lol AAx.lol test.sh My goal is to create a script (test.sh) which renames all the files to their original name without AA. I want to end up with this: b.lol c.lol x.lol Using sed how is it possible? i tried to write the script ... (3 Replies)
Discussion started by: anishkumarv
3 Replies

6. Shell Programming and Scripting

Renaming Movies (or Flipping Portions of Filenames Using sed or awk)

Hey folks My problem is simple. For my first stash of movies, I used a naming convention of YEAR_MOVIE_NAME__QUALITY/ for each movie folder. For example, if I had a 1080p print of Minority Report, it would be 2002_Minority_Report__1080p/. The 2nd time around, I changed the naming convention... (4 Replies)
Discussion started by: ksk
4 Replies

7. Shell Programming and Scripting

Sed Question 1. (Don't quite know how to use sed! Thanks)

Write a sed script to extract the year, rank, and stock for the most recent 10 years available in the file top10_mktval.csv, and output in the following format: ------------------------------ YEAR |RANK| STOCK ------------------------------ 2007 | 1 | Exxon... (1 Reply)
Discussion started by: beibeiatNY
1 Replies

8. UNIX for Dummies Questions & Answers

Cutting In Unix Question

Please Delete! Thanks. (7 Replies)
Discussion started by: Shiruken
7 Replies

9. Shell Programming and Scripting

need help cutting consecutive lines with sed or awk

HI All, I want to cut 5 lines after a pattern using sed or awk. can any one tell me how to do it ? (2 Replies)
Discussion started by: raghin
2 Replies

10. UNIX for Dummies Questions & Answers

Cutting lines out using sed I presume.

Happy New Year!!! I'm trying to cut out some text in a data file where I only want the first line and the last line. For example. 1. Colin Was here <<-- Text I want to cut out 2. THIS IS THE TEXT I WANT TO CUT <- CUT THIS OUT 3. OUT BECAUSE IT'S NO GOOD TO ME <- CUT THIS OUT 4. I... (5 Replies)
Discussion started by: cfoxwell
5 Replies
Login or Register to Ask a Question