Solved

Unix , append value from file to the file name

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now