Solved

Unix , append value from file to the file name

Posted on 2014-01-13
2
355 Views
Last Modified: 2014-01-16
Hi
I have file whose name to be appended by a value in the same file

The value starts from the position 10 and ends at position 30 , this value is same in  the whole file. We have  to trim the spaces if it has any spaces at its end.
the file is fixed width file

example
filename:   test1

values in test1

abc       34rtst               kkkkdafdf
kfl         34rtst               kjdfada;lk
dfa        34rtst               adddfjadf

the file name should be renamed to test1_34rtst
0
Comment
Question by:uco
2 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 39778312
perl -ne 'rename $ARGV,$ARGV."_".(/.{9}(\S{1,20})/)[0] or die "$ARGV $!";last' test1
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 39780675
or a non-perl solution

mv file1 file1_$(head -1 test1|cut -c10-30)

Note that because no quotes are used, any whitespace is automatically discarded.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question