?
Solved

Extracting a file name from the file data

Posted on 2000-01-03
1
Medium Priority
?
151 Views
Last Modified: 2012-05-04
I need to rename a file I am receiving from an application.  The  file name I want to use is on the first line of the file (eg. /* trans1.wtn */)  I want the file name to be trans1.wtn.  What series of commands do I use to extract the name and then re-name the file?
0
Comment
Question by:jshartig
1 Comment
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 200 total points
ID: 2321295
Assuming it is always in the form '/* name */', this should work just fine in a shell script:

head -1 "$filename" | awk '{ print $2 }' | read newname
mv "$filename" "$newname"
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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 video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month5 days, 8 hours left to enroll

588 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