Solved

Unix , append value from file to the file name

Posted on 2014-01-13
2
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell Split 18 43
unix how to search all linked and hidden files in current directory 5 22
powershell script error 2 36
[bash] complex parsing 9 34
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
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 …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

739 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