?
Solved

Unix , append value from file to the file name

Posted on 2014-01-13
2
Medium Priority
?
360 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 2000 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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

719 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