[英]Please help writing unix script for the below scenario
There is an unload.dat
file with the list of .ksh
file names.有一个带有
.ksh
文件名列表的unload.dat
文件。 The task is to extract a few parameter details from each of the files that are present in the unload.dat
file.任务是从存在于
unload.dat
文件中的每个文件中提取一些参数详细信息。 Every file contains the below information.每个文件都包含以下信息。
Let us consider for first file name ( file_name1.ksh
) in the unload.dat
:让我们考虑
unload.dat
中的第一个文件名( file_name1.ksh
):
graph_name = abcd.ksh
export name_a=value_a
export "name_b=value_b"
export name_c=value_c
export name_d=value_d
export name_e="value_e"
export name_f="value_f"
The next file's fetched data should be appended to the previous file's output in the same output file.下一个文件获取的数据应该附加到同一个 output 文件中的上一个文件的 output 中。
The output should look like the below: output 应如下所示:
abcd.ksh name_a value_a 1 filename_1.ksh
abcd.ksh name_b value_b 1 filename_1.ksh
abcd.ksh name_c value_c 1 filename_1.ksh
abcd.ksh name_d value_d 1 filename_1.ksh
abcd.ksh name_e value_e 1 filename_1.ksh
abcd.ksh name_a value_a 2 filename_2.ksh
abcd.ksh name_b value_b 2 filename_2.ksh
abcd.ksh name_c value_c 2 filename_2.ksh
abcd.ksh name_d value_d 2 filename_2.ksh
abcd.ksh name_e value_e 2 filename_2.ksh
#!/bin/sh
counter=1
while read -r filename; do
if [ "$counter" -ne 1 ]; then
echo
echo
fi
IFS== read _ graph < "$filename"
graph=${graph# }
sed -n '/^export/{s/^[^ ]* //;s/"//g;p}' < "$filename" \
| while IFS== read -r name value; do
echo "$graph $name $value $counter $filename"
done
counter=$((counter+1))
done < unload.dat
#!/bin/bash
var1=`cat unisc.txt | sed -n '1,1p' | cut -f3 -d' '`
var2=`cat unisc.txt | wc -l`
va1=1
var=`expr $var2 - 1`
echo $var
for ((i=1;i<=2;i++))
do
for ((j=1;j<=$var;j++))
do
var3=`sed 's/"//g' unisc.txt | cut -f2 -d' ' | cut -f1 -d'=' | sed -n '2,'$var2'p' | sed -n $j'p'`
var4=`sed 's/"//g' unisc.txt | cut -f2 -d' ' | cut -f2 -d'=' | sed -n '2,'$var2'p' | sed -n $j'p'`
echo "$var1 $var3 $var4 $i filename_1.ksh"
done
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.