Informatica Pre Session Command读取目录中与模式匹配的文件,并删除文件中的“”

问题描述

我做了很多研究,最后决定提出这个问题。我正在使用@R_635_4045@ica 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,然后重定向到moves到原始文件名。

为您提供了两个不同的代码,以使您清楚地理解它。您可以将其合并为一个脚本,然后在informatica会话前命令中调用它