Solved

Unix , append value from file to the file name

Posted on 2014-01-13
2
359 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

617 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