[Solved] Search, Extract and Rename Multiple Files - Page 2 | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Unix/Linux Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

[Solved] Search, Extract and Rename Multiple Files

UNIX for Dummies Questions & Answers


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 02-26-2014
Akshay Hegde's Unix or Linux Image
Akshay Hegde Akshay Hegde is offline Forum Advisor  
Forum Advisor
 
Join Date: Nov 2012
Last Activity: 31 March 2015, 7:44 AM EDT
Location: Goa / Bangalore, India
Posts: 1,690
Thanks: 84
Thanked 566 Times in 515 Posts
Try this I modified...


Code:
ls *-*-*.csv -1 | \
		awk -F'[-,]' 'FNR==NR{
					gname = substr($2,1,10)
					gsub(/[[:space:]]/,"\\ ",gname)
					A[$1] = gname
					next
				     }
                            ($1 in A){
					print "cp "$0,A[$1]"-"$0
				     }' group.csv -  | sh

---------- Post updated Feb 27th, 2014 at 03:37 AM ---------- Previous update was Feb 26th, 2014 at 11:12 PM ----------

I can't produce this Power Too -750416394-RE-file258.csv , there is only one space not two check od -c file
The Following User Says Thank You to Akshay Hegde For This Useful Post:
armsaran (02-27-2014)
Sponsored Links
    #9  
Old Unix and Linux 02-26-2014
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 31 March 2015, 10:50 PM EDT
Location: San Jose, CA, USA
Posts: 5,957
Thanks: 242
Thanked 1,990 Times in 1,697 Posts
Quote:
Originally Posted by armsaran View Post


Thanks Don.
Code is not restricted for the first 10 chars
Output file as per your code

Code:
HB280RS_CDEF_CorporateEvent-750383990-RE-file26.csv
HB273_CDEF_November_corporate_event-750343656-RE-file89.csv
Copy of Gardening Category Clickers-750400039-RE-file277.csv

Note that I had posted a fix for this about an hour before you sent this message. I had been working on a solution based on your original requirements and didn't notice your updated requirements until after my initial post. The updated code is:

Code:
ls *.csv | awk -F, '
NR == 1 { next }
FNR == NR { c[$1] = substr($2, 1, 10); next }
$1 in c { printf("mv \"%s\" \"%s-%s\"\n", $0, c[$1], $0)
}' Group.csv FS='-' - | sh

The difference between my code and Akshay's code is that my code quotes both operands to mv while Akshay's code changes each occurrence of a <space>, <form-feed>, <carriage-return>, <tab>, or <vertical-tab> character to an escaped <space> character in the destination operand to mv but doesn't protect any characters in class space in the source operand.
Sponsored Links
    #10  
Old Unix and Linux 02-27-2014
armsaran armsaran is offline
Registered User
 
Join Date: Feb 2014
Last Activity: 20 March 2014, 6:49 AM EDT
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Thanks Don.

Its working fine
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rename multiple files juzz4fun Shell Programming and Scripting 3 05-20-2013 09:57 PM
[SOLVED] Rename multiple files lost.identity UNIX for Dummies Questions & Answers 8 12-06-2012 06:11 AM
Rename multiple files sylcam Shell Programming and Scripting 4 08-16-2011 01:02 PM
Using AWK: Extract data from multiple files and output to multiple new files Liverpaul09 UNIX for Dummies Questions & Answers 3 10-12-2010 03:59 AM
rename multiple files from search output woodstock UNIX for Dummies Questions & Answers 5 01-06-2009 04:51 PM



All times are GMT -4. The time now is 11:10 PM.