【问题标题】:Informatica Pre Session Command read files matching a pattern inside a directory and delete "" in filesInformatica Pre Session 命令读取目录中匹配模式的文件并删除文件中的“”
【发布时间】:2020-12-21 06:44:42
【问题描述】:

我研究了很多,最后决定提出这个问题。我正在使用 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

【问题讨论】:

  • 您正在寻找-i 选项的sed 工具。在单个文件上尝试此操作,然后您也可以在多个文件上运行此操作sed -i 's/\"//g' Input_file 这将删除所有出现的" 并将更改保存到 Input_file 本身。
  • 那么 for 循环是否正确?只需将 -i 放在 sed 前面并为多个文件运行 for 循环命令就可以了?

标签: shell unix etl informatica informatica-powercenter


【解决方案1】:

请使用以下脚本,

替换双引号

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 会话前命令中调用它

【讨论】:

  • -i 选项通过将原始文件自动替换为输出来执行就地更改。因此,您可以将其添加到第一个 sn-p 并从两者中删除 > tmp && mv tmp "$file"; 部分。请参考archive.is/cLlnm#selection-795.0-829.59
猜你喜欢
  • 2010-10-06
  • 2020-01-23
  • 2017-03-18
  • 2015-04-25
  • 2016-03-08
  • 2021-11-24
  • 2016-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多