LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-13-2014, 01:29 PM   #1
hwang163
LQ Newbie
 
Registered: Jun 2014
Posts: 1

Rep: Reputation: Disabled
shell script command for file modification


Hello, Linux community, I'm new to Linux. I'm running a simulation package on Linux. For each iteration, a file as below will be generated. I need to do some modification and then use the modified file as an input for the next iteration. I want to finish this modification by shell script then I don't need to do it manually after each iteration. The modification is as follows: there are x y z coordinates from the 9th line (below Direct). The third column of each line should be multiplied by a constant (say 1.03).

How should I do it in shell script?
Thank you!

******The generated file starts from next line

POSCAR for FCC Cu (created manually)

1.00000000000000

7.6799999999999997 0.0000000000000000 0.0000000000000000

3.8399999999999999 6.6509999999999998 0.0000000000000000

0.0000000000000000 0.0000000000000000 41.0000000000000000

72 40 40

Selective dynamics

Direct

0.0000000000000000 0.0000000000000000 1.0000000000000000 F F F

0.9999979999999979 0.3328410000000019 1.0000000000000000 F F F

0.9999960000000030 0.6656819999999968 0.0000000000000000 F F F

0.3328369999999978 0.0000000000000000 0.0000000000000000 F F F

0.3328360000000004 0.3328410000000019 2.0000000000000000 F F F

0.3328339999999983 0.6656819999999968 3.0000000000000000 F F F

0.6656750000000002 0.0000000000000000 5.0000000000000000 F F F

0.6656729999999982 0.3328410000000019 2.0000000000000000 F F F

0.6656710000000032 0.6656819999999968 1.0000000000000000 F F F

Last edited by hwang163; 06-13-2014 at 01:30 PM.
 
Old 06-13-2014, 02:15 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by hwang163 View Post
Hello, Linux community, I'm new to Linux. I'm running a simulation package on Linux. For each iteration, a file as below will be generated. I need to do some modification and then use the modified file as an input for the next iteration. I want to finish this modification by shell script then I don't need to do it manually after each iteration. The modification is as follows: there are x y z coordinates from the 9th line (below Direct). The third column of each line should be multiplied by a constant (say 1.03). How should I do it in shell script?
Code:
POSCAR for FCC Cu (created manually)

1.00000000000000
 7.6799999999999997    0.0000000000000000    0.0000000000000000
 3.8399999999999999    6.6509999999999998    0.0000000000000000
 0.0000000000000000    0.0000000000000000   41.0000000000000000
72 40 40

Selective dynamics Direct

0.0000000000000000 0.0000000000000000 1.0000000000000000 F F F
0.9999979999999979 0.3328410000000019 1.0000000000000000 F F F
0.9999960000000030 0.6656819999999968 0.0000000000000000 F F F
0.3328369999999978 0.0000000000000000 0.0000000000000000 F F F
0.3328360000000004 0.3328410000000019 2.0000000000000000 F F F
0.3328339999999983 0.6656819999999968 3.0000000000000000 F F F
0.6656750000000002 0.0000000000000000 5.0000000000000000 F F F
0.6656729999999982 0.3328410000000019 2.0000000000000000 F F F
0.6656710000000032 0.6656819999999968 1.0000000000000000 F F F
Post what you've written/tried so far, and tell us where you're stuck. But we're not going to write your shell scripts for you...there are MANY thousands of tutorials you can find on Google for bash shell scripting, and manipulating files. They have examples and ample explanations, and should be able to get you started. There is even a tutorial in my posting signature.

Show us what you've done/tried, and we'll help. If you only want the 9th line, you can either use awk or sed to do this. For example:
Code:
awk 'NR==9{print $0}' filename   ***OR***   sed 9!d filename

Last edited by TB0ne; 06-13-2014 at 02:19 PM.
 
Old 06-14-2014, 01:20 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Awk would probably be my choice as it can also perform the arithmetic you need easily.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] cd command in shell script returns: No such file or directory edi_corey Linux - Newbie 9 02-10-2012 06:01 AM
Redirect output of a command to another file inside shell script mukul_d Linux - General 4 08-27-2010 02:23 PM
shell script read line from file, use it in command DiGiGoth Programming 5 08-31-2008 11:08 AM
command or shell script to print line range from file minil Programming 3 12-28-2005 08:05 AM
Script File: Parsing command sent to shell cheema Programming 1 07-01-2005 12:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration