Shell Informatica会话前命令读取目录中与模式匹配的文件并删除"&引用;归档

Shell Informatica会话前命令读取目录中与模式匹配的文件并删除"&引用;归档,shell,unix,etl,informatica,informatica-powercenter,Shell,Unix,Etl,Informatica,Informatica Powercenter,我做了很多研究,最后决定提出这个问题。我正在使用Informatica Pre-Session命令读取与特定模式匹配的文件,并删除这些文件中的所有“”字符。 同样,一旦完成,我需要删除最后一行 在单个文件上,我可以使用以下方法完成此操作: #To remove Double Quotes from the file sed -i -e 's/\"//g' /opt/informed/file_name_20200801.txt # This works for individual

我做了很多研究,最后决定提出这个问题。我正在使用Informatica Pre-Session命令读取与特定模式匹配的文件,并删除这些文件中的所有“”字符。 同样,一旦完成,我需要删除最后一行

在单个文件上,我可以使用以下方法完成此操作:

#To remove Double Quotes from the file

sed -i -e 's/\"//g' /opt/informed/file_name_20200801.txt

# This works for individual files but next I'm trying to loop through a directory 
#with matching file names and delete quotes in all files in the directory

for file in opt/informed/file_name_*.txt; do 
        sed 's/\"//g' "$file" >> /opt/informed/"$file";
done;

#It runs without error but nothing happens. I want to edit the existing files to get rid of 
#any double quotes in those files. ```

#Once I'm able to achieve that, I can apply a similar loop to process the files 
#to delete last #line of each file using:

sed -e '$d' /opt/informed/filename.txt >> filename.txt #Works for individual Files

请使用下面的脚本

替换双引号

for file in opt/informed/file_name_*.txt; 
do 
        sed 's/\"//g' "$file" > tmp && mv tmp "$file";
done;
删除标题

for file in opt/informed/file_name_*.txt;  
do 
    sed -i '$d' "$file" > tmp && mv tmp "$file";
done;
代码循环每个文件并重定向到
tmp
,然后
移动到原始文件名


为您提供了两种不同的代码以清楚地理解它。您可以将其合并到单个脚本中,并在informatica pre session command中调用它

您正在为
sed
工具寻找
-i
选项。在单个文件上尝试此操作,然后您也可以在多个文件上运行此操作。
sed-i的//\“//g”Input\u文件
这将删除所有出现的
,并将更改保存到Input\u文件本身。for循环是否正确?只需将-i放在sed前面并对多个文件运行for-loop命令就可以了。
-i
选项通过自动将原始文件替换为输出来执行就地更改。因此,您可以将其添加到第一个代码段中,并删除
>tmp&&mvtmp“$file”两个部分的一部分。请参阅