如何在csh脚本中忽略第一行并读取和存储第二行文本文件的值?



我有一个文本文件,其中的数据以这种格式存储-

Sample|Name|Date|Value1|Value2|Value3
Example|shell|20210825|1400.67|1456.98|1234.56

现在我想只从这个文本文件打印值到另一个文本文件使用如下的自动脚本-

Value 1 is: 1400.67
Value 2 is: 1456.98
Value 3 is: 1234.56

我已经尝试了bash脚本,但bash脚本,但我只需要shell脚本,因为它是强制使用shell脚本。

#!/bin/bash
OLDIFS=$IFS
IFS="|"
filename=Sample.txt
{
read 
while read f1 f2 f3 f4 f5 f6
do
echo "Value 1 is: [$f4]
Value 2 is: [$f5]
Value 3 is: [$f6]
" > output.txt
done
} < ${filename}
IFS=$OLDIFS

如果有人在这方面有任何工作,请帮助!提前感谢;)

这是一个可能的解决方案

#!/bin/csh
set filename = "Sample.txt"
echo > output.txt
foreach line ( "`sed '1d' $filename`" )
set argv = ($line:as/|/ /)
echo "Value 1 is: [$4]" >> output.txt
echo "Value 2 is: [$5]" >> output.txt
echo "Value 3 is: [$6]" >> output.txt
echo >> output.txt
end

最新更新