-1

I have three columns of data in one file, i.e.

  0.464980006         0.237939999         0.000000000
  0.464980006         0.737940013         0.000000000
  0.964980006         0.237939999         0.000000000
  0.964980006         0.737940013         0.000000000
  0.298310012         0.404610008         0.068700001
  0.298310012         0.904609978         0.068700001
  0.798309982         0.404610008         0.068700001
  0.798309982         0.904609978         0.068700001

Now I want to append F F F to the end of each line, how should I achieve it?

Here is my code:

#!/bin/bash
tail -n +9 POSCAR | head -n 24 | sort -k3 | head -8 > o-bot-layer
tail -n +9 POSCAR | head -n 24 | sort -k3 | tail -16 > o-sur-layer
tail -n +33 POSCAR | sort -k3 | head -4 > ce-bot-layer
tail -n +33 POSCAR | sort -k3 | tail -8 > ce-sur-layer

cat o-bot-layer | awk '{print $1,$2,$3,"F F F"}' > o-bot-layer

head -n 8 POSCAR > lat

cat o-sur-layer >> lat
cat o-bot-layer >> lat
cat ce-sur-layer >> lat
cat ce-bot-layer >> lat
mv lat pos.str
rm o-sur-layer o-bot-layer ce-sur-layer ce-bot-layer

It doesn't work. I tried sed 's/$' and awk '{print $0, ""}' in other people's post, the weird thing is I only get it append to the beginning of the line, not the end.

Something like this:

 F F F0002 0.571280003 0.137400001
  F F F0017 0.071280003 0.137400001
  F F F0017 0.571280003 0.137400001
  F F F0006 0.237939999 0.206110001
  F F F0006 0.737940013 0.206110001
  F F F0006 0.237939999 0.206110001
  F F F0006 0.737940013 0.206110001
  F F F0012 0.404610008 0.274809986
  F F F0012 0.904609978 0.274809986
  F F F9982 0.404610008 0.274809986
  F F F9982 0.904609978 0.274809986
  F F F0002 0.071280003 0.343510002
  F F F0002 0.571280003 0.343510002
  F F F0017 0.071280003 0.343510002
  F F F0017 0.571280003 0.343510002
  F F F0006 0.237939999 0.000000000
  F F F0006 0.737940013 0.000000000
  F F F0006 0.237939999 0.000000000
  F F F0006 0.737940013 0.000000000
  F F F0012 0.404610008 0.068700001
  F F F0012 0.904609978 0.068700001
  F F F9982 0.404610008 0.068700001
  F F F9982 0.904609978 0.068700001
  F F F0012 0.404610008 0.171749994
  F F F0012 0.904609978 0.171749994
  F F F9982 0.404610008 0.171749994

I suspect there are some hidden thing in my file format, something like \n at the beginning of each line so sed $s would think the beginning of line is the end of line. I am not sure...

Thank you!

Lei Zhang
  • 103
  • 1
  • 2
  • 7

2 Answers2

1

Oh, my goodness. I got it.

The file POSCAR I got is fishy.

I guess it is from windows, so it contains some dos format that can be misleading in unix environment.

I first convert it using

dos2unix POSCAR

and then run my code, everything now works fine, just like other people's post!

Any guru can explain it further this fishy dos format?

Lei Zhang
  • 103
  • 1
  • 2
  • 7
  • It's the line endings: different OSs use different newline representations, see https://en.wikipedia.org/wiki/Newline – Benjamin W. May 14 '16 at 03:15
0
  • First thing what is the source of the file POSCAR
  • if you copy paste, there is possibility of the non displayable chars
  • i tried to browsed through and found out, might you it will help you to find the source

    Unicode Character 'START OF TEXT' (U+0002)
    Unicode Character 'DEVICE CONTROL TWO' (U+0012)
    Unicode Character 'END OF TRANSMISSION BLOCK' (U+0017)
    

Any ways see if this helps

sed -E 's;^(.*);F F F\1;g' POSCAR
Sanjeev
  • 107
  • 6